improve email format

This commit is contained in:
陆柯 2023-07-26 13:32:35 +08:00
parent 40db44fc75
commit a256e4fc34

View File

@ -19,8 +19,23 @@ module.exports = {
}
},
/*
- https://regex101.com/r/3uvtNl/1
/^((?:[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~]|(?<=^|\.)"|"(?=$|\.|@)|(?<=".*)[ .](?=.*")|(?<!\.)\.){1,64})(@)((?:[A-Za-z0-9.\-])*(?:[A-Za-z0-9])\.(?:[A-Za-z0-9]){2,})$/
- https://emailregex.com/
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
*/
validate_email ({ email, format } = {}) {
if (format) return new RegExp(format).test(email)
return /^.+@[^\.]+\..+$/.test(email)
let regex =
/^((?:[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~]|(?<=^|\.)"|"(?=$|\.|@)|(?<=".*)[ .](?=.*")|(?<!\.)\.){1,64})(@)((?:[A-Za-z0-9.\-])*(?:[A-Za-z0-9])\.(?:[A-Za-z0-9]){2,})$/
try {
if (typeof format === 'string') {
regex = new RegExp(format)
}
} catch (exp) {
console.log('Invalid email format: ', format)
}
return regex.test(email)
},
}