Am trying to validate an Email id field in angularJs using ng-pattern directive.
But am new to AngularJs. I need to show an error message as soon as the user enters the wrong email id.
The code which I have below is am trying to solve. Help me out with using ng-pattern for getting the proper result.
<script type="text/javascript" src="/Login/script/ang.js"></script>
<script type="text/javascript">
function Ctrl($scope) {
$scope.text = 'enter email';
$scope.word = /^[a-z]+[a-z0-9._]+@[a-z]+\.[a-z.]{2,5}$/;
}
</script>
</head>
<body>
<form name="myform" ng-controller="Ctrl">
<input type="text" ng-pattern="word" name="email">
<span class="error" ng-show="myform.email.$error.pattern">
invalid email!
</span>
<input type="submit" value="submit">
</form>
</body>
Spend some time to make it working for me.
Requirement:
single or comma separated list of e-mails with domains ending name.surname@gmail.com or team-email@list.gmail.com
Controller:
HTML:
I found good online regex testing tool. Covered my regex with tests:
https://regex101.com/r/Dg2iAZ/6/tests
According to the answer of @scx ,I created a validation for GUI
And simply add :
css
html
I tried @Joanna's method and tested on the following websites and it didn't work.
I then modified it to and it worked.
There is nice example how to deal with this kind of problem modyfing built-in validators angulardocs. I have only added more strict validation pattern.
And simply add
I have tried wit the below regex it is working fine.
Email validation : \w+([-+.']\w+)@\w+([-.]\w+).\w+([-.]\w+)*