javascript - Regular expression to not allow spaces anywhere in the email -
i trying validate email address using regular expression such throws error if white spaces added anywhere in email. current regex using this:
<input type="email" class="form-control" name="username" ng- model="username" id="email" placeholder="email" ng-pattern='/^(([^<>()\ [\]\\.,;:\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,}))$/' required /> <span ng-show="login.username.$error.pattern">this email format invalid! </span>
the problem allows me add white spaces in end. how can modify if add whitespace in end error message fired?
the newest release of angularjs (1.5.7) includes email address validation improvements.
you can check commit here.
line 28 corresponds committed regex:
var email_regexp = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+\/0-9=?a-z^_`a-z{|}~]+(\.[-!#$%&'*+\/0-9=?a-z^_`a-z{|}~]+)*@[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])?)*$/;
below directive's code have tests validate regex. check white spaces.
Comments
Post a Comment