javascript - I think i have a wrong pattern of AngularJS email or what? -


this video

i put spaces in front @ mark submit button doesn't disappear, why? still wrong mistake value , want submit button disapear.

my code this

<html> <head>     <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>     <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-resource.min.js"></script> </head> <body ng-app="ctrljs">     <form name='myform' ng-controller='formctrl'>         <input type='email' name='email' ng-model='email' required ng-pattern="/^[a-za-z0-9._%+-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/">         <span ng-show='myform.email.$error.email'> <font color='red'>invalid email</font></span>         <input type='submit' value='submit' ng-hide="!myform.$valid"></input>     </form>     <script>         var app = angular.module('ctrljs', []);         app.controller('formctrl', function($scope, $http){           $scope.digits = {};         });     </script> </body> </html> 

help me please, thank you.

the email valid because angular trim whitespace you. see example below. if type space before example. see become valid.

var app = angular.module('ctrljs', []);  app.controller('formctrl', function($scope, $http) {    $scope.email = "   example@example.com";  });
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script>    <body ng-app="ctrljs">    <form name='myform' ng-controller='formctrl'>      <pre>{{email}}</pre>      <input type='email' name='email' ng-model='email' required ng-pattern="/^[a-za-z0-9._%+-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/">      <span ng-show='myform.email.$error.email'> <font color='red'>invalid email</font></span>      <input type='submit' value='submit' ng-hide="!myform.$valid">    </form>  </body>

unfortunately there no ng-trim type="email" see docs here:

https://docs.angularjs.org/api/ng/input/input%5bemail%5d

if want prevent auto trimming happening have monkey patch.


also doc, type=email input has built in validation using regex in file: https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js

you don't need provide own unless need stricter or looser validation.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -