如果用户从几个特定区域输入电子邮件,我想显示错误消息。我试过了,但没有解决。
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 />
xyz@domain.com或 不允许xyz@DOMAIN.com。
答案 0 :(得分:0)
Javascript:
const regex = /^[a-zA-Z0-9_.+-]+@((domain|domain1|domain)).com$/;
const str = `xyz@domain1.com`;
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}`);
});
}
答案 1 :(得分:0)
您可以通过外部JavaScript函数检查邮件地址:
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 />