mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-04 00:08:21 +00:00
Relax constraints for UserID email address validity (#1641)
New checks align with the HTML5 W3C spec and should be more lax than the existing ones (meaning, addresses which passed validation before should continue to be valid). Addresses such as `@localhost` are now allowed too, since presence of "." is no longer enforced. These checks should not be considered exhaustive: library users are encouraged to implement separate checks for email validity if needed. Co-authored-by: Daniel Huigens <d.huigens@protonmail.com>
This commit is contained in:
@@ -457,11 +457,17 @@ const util = {
|
||||
return os.cpus().length;
|
||||
},
|
||||
|
||||
/**
|
||||
* Test email format based on W3C HTML5 specification.
|
||||
* This check is not exaustive, and does not match RFC 5322 exactly
|
||||
* (see https://html.spec.whatwg.org/multipage/input.html#email-state-(type=email)),
|
||||
* but is commonly used for email address validation.
|
||||
*/
|
||||
isEmailAddress: function(data) {
|
||||
if (!util.isString(data)) {
|
||||
return false;
|
||||
}
|
||||
const re = /^(([^<>()[\]\\.,;:\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,}[0-9]*|xn--[a-zA-Z\-0-9]+)))$/;
|
||||
const re = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
return re.test(data);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user