Ehsan Akbar Ehsan Akbar - 6 months ago 12
Javascript Question

ng-show="frm.Email.$error.email " doesn't show the error of invalid email

I am trying to create a login form in mvc-asp.net with angularjs validation ,

here is my code :

<span style="color:red" ng-show="frm.Email.$dirty || frm.Email.$invalid">
<span ng-show="frm.Email.$error.required">ایمیل را وارد کنید</span>
<span ng-show="frm.Email.$error.email">ایمیل وارد شده نامعتبر است</span>
</span>


when i leave the textbox empty the error is appeared
frm.Email.$error.required
but when i enter an invalid email
mike.com
the error of
ng-show="frm.Email.$error.email
doesn't appear.why?

Answer

It seems you are using <input type="text">. For email, you should use <input type="email">. To validate email address, Angular use HTML5 valid and invalid controls.