Deric Lima Deric Lima - 1 month ago 18
AngularJS Question

Email Validation with AngularJS 1.2.0

I'm doing email validation with Angular out of box and works like must be.

<input class="form-control" type="email" placeholder="johndoe@example.com"
name="email" ng-model="user.email" required/>
<div class="error-block" ng-if="form.$submitted && form.email.$invalid">
<div ng-if="form.email.$error.required">Enter the Email Address</div>
<div ng-if="form.email.$error.email">Invalid email address.</div>


The problem is that when the user insert a domain with more than 6 characters, Angular complain about it. For instance if I try to use the email
dericlima@company.company
, Angular set the email like Invalid.

But if I set the email
dericlima@company.compan
, Angular validate the email without problems.
Do I have some way to extend the regex to more than 6 characters or I need to use
ng-pattern
?

Thanks guys

Answer

This behaviour was fixed in angular v1.2.10. You might either have to update to that version or use ng-patter with regular expression from this commit from angular repository.

Also, I'd advise you to look into this article about email regexp checking.