1

I am using ng-pattern-restrict to prevent people from entering invalid emails according to valid email addresses at https://en.wikipedia.org/wiki/Email_address Here is what I have so far:

^([\w!#$%&'*/~|`}{^+-]+(.|@)?)*$

This will prevent .@ from occurring next to one another. It also prevents from @. from appearing at the beginning. Notice I do not care if the expression is blank as required tag in my input field will not allow submission unless the form is filled out. What I can not figure out is after @ is in the expression it should be prevented from used again. Any ideas?

Auguste
  • 2,007
  • 2
  • 17
  • 25
John
  • 11
  • 1
  • Why not just look for any combination of numbers and letters, a literal '@', any combination of letters, a literal '.', and then any combination of letters? – Thomas Murphy Jun 06 '16 at 21:05
  • _"What regex to use to validate email address"_ has been asked on SO seven-thousand-three-hundred-and-nineteen times. The answer is ***"don't"***. Especially now with HTML5, you can use `` – Stephen P Jun 06 '16 at 22:00
  • 1
    Possible duplicate of [Using a regular expression to validate an email address](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) – Stephen P Jun 06 '16 at 22:01
  • _"It also prevents from @. from appearing at the beginning."_ **and** _"after @ is in the expression it should be prevented from used again."_ — Both of these rules would exclude legal (valid) email addresses. Email is `address@domain` and the `address` part can be _absolutely anything in the world_ if it is properly escaped, because it is _up to the `domain` part_ to make sense of it. – Stephen P Jun 06 '16 at 22:05

0 Answers0