improve email format
This commit is contained in:
parent
40db44fc75
commit
a256e4fc34
19
i18n-tool.js
19
i18n-tool.js
@ -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)
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user