We use regular expressions to validate email address in JavaScript or in jQuery. In AngularJS, we can easily validate whether user entered valid email address or not using $error.email.
<!DOCTYPE html> <html> <head> <script src="scripts/angular.min.js"> </script> </head> <body> <form name="myForm" ng-app> <input type="email" name="EmailId" ng-model="UserEmail" required placeholder="Enter your Email Id" /> <br /> <div style="color:red;font-weight:bold;" ng-show="myForm.EmailId.$error.email">Invalid Email id</div> </form> </body> </html>
As shown, we are using $error.email for EmailId textbox. While entering data in EmailId textbox, it shows error message as “Invalid Email Id” until you enter correct email address as shown below.