سؤال

Sample email: some@mail

In Angular v1.1.x this email is not valid. But in Angular v1.3.x it's valid. I know technically it's valid but I need like some@valid.com email. I tried some regex but not worked.

How can I change validation in Angular v1.3.x ?

هل كانت مفيدة؟

المحلول

Try to use ng-pattern in your email input.

<input type="email" name="input" ng-model="text" ng-pattern="/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,15})$/" required>

See an example: plunk

نصائح أخرى

Now this got even better, Angular 4 has email validator built-in, there is no boilerplate code needed :)

https://github.com/angular/angular/blob/master/CHANGELOG.md#features-6 https://github.com/angular/angular/pull/13709

Just add email to the tag. For example

  <form #f="ngForm">
    <input type="email" ngModel name="email" required email>
    <button [disabled]="!f.valid">Submit</button>
    <p>Form State: {{f.valid?'VALID':'INVALID'}}</p>
  </form>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top