Email Validation in AngularJS

Last Reply 7 months ago By dharmendr

Posted 7 months ago

How to validate email address in angularjs

Posted 7 months ago Modified on 7 months ago

Hi rani,

Check this example. Now please take its reference and correct your code.

HTML

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script type="text/javascript">
    var app = angular.module('MyApp', []);
    app.controller('MyController', function ($scope) { });
</script>
<div ng-app="MyApp" ng-controller="MyController">
    <form name="myForm">
    Email:<input type="text" name="email" ng-model="txtEmail" ng-pattern="/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/" />
    <span style="color: Red" ng-show="myForm.email.$dirty && myForm.email.$error.pattern">Invalid email address.</span>
    </form>
</div>

Demo