I have a form which I need to verify internet routable email addresses before submission and deny local routing. Both ng-pattern="email.text"
and ng-pattern="email"
pass bob@bob
which should fail, as these are customer email addresses outside of the local network.
The following do not give me what I'm looking for (many are using rudimentary RegExs that don't fully conform to RFC standards or don't deny local routing):
- How to validate email id in angularJs using ng-pattern
- Form Validation - Email Validation not working as expected in AngularJs
- Validate email address in JavaScript?
Reading http://www.regular-expressions.info/email.html it references RFC 5322
with regular expression:
\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
| "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]
| \\[\x01-\x09\x0b\x0c\x0e-\x7f])*")
@ (?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
| \[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:
(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]
| \\[\x01-\x09\x0b\x0c\x0e-\x7f])+)
\])\z
Is there a way to make the above into a RegEx that requires a tld-type
, so it is internet routable? Specifically, where I can use it in a ng-pattern
, like ng-pattern="<regex goes here>"
in the form?