Reputation: 305
I want to show error message if user enter the email from few specific doamins. I tried this but didn't work out.
Email <input type="text" name="email" ng-model="txtmail" ng-pattern="/^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+\.)?[a-zA-Z]+\.)?(?!(domain|domain1|domain3))\.com$/" required />
[email protected] or [email protected] should not be allowed.
Upvotes: 0
Views: 1600
Reputation: 5138
You can check the mail address via external JavaScript function:
let success = () => {console.log("Valid address")};
let fail = () => {console.log("ERROR - Invalid address")};
let regex = /^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+\.)?[a-zA-Z]+\.)?(domain|domain1|domain3)\.com$/g;
function checkInput(element) {
if(regex.test(element.value)) {
fail();
}
else {
success();
}
}
Email <input type="text" name="email" onchange="checkInput(this)" ng-model="txtmail" required />
Upvotes: 2
Reputation: 11884
Javascript:
const regex = /^[a-zA-Z0-9_.+-]+@((domain|domain1|domain)).com$/;
const str = `[email protected]`;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Upvotes: 1