Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想我的AngularJS邮件模式有误还是怎么了?_Javascript_Angularjs - Fatal编程技术网

Javascript 我想我的AngularJS邮件模式有误还是怎么了?

Javascript 我想我的AngularJS邮件模式有误还是怎么了?,javascript,angularjs,Javascript,Angularjs,这是我的 我在@标记前面加了一些空格,但是提交按钮没有消失,为什么?这仍然是一个错误的值,我想取消提交按钮 我的代码是这样的 <html> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angul

这是我的

我在@标记前面加了一些空格,但是提交按钮没有消失,为什么?这仍然是一个错误的值,我想取消提交按钮

我的代码是这样的

<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>

无效电子邮件
var app=angular.module('ctrljs',[]);
app.controller('formctrl',函数($scope,$http){
$scope.digits={};
});

请帮帮我,谢谢。

这封电子邮件是有效的,因为angular会帮你删掉空白。请参见下面的示例。如果在示例之前键入空格。你会看到它变得有效

var-app=angular.module('ctrljs',[]);
app.controller('formctrl',函数($scope,$http){
$scope.email=”example@example.com";
});

{{email}}
无效电子邮件

Hmm。。。在检查是否为有效电子邮件之前,您可能应该对该值进行修剪。或者保持原样,让用户在邮件的前面或末尾添加空格。我认为这是一个相当好的用户体验。然后在服务器端修剪值并删除字符串开头和结尾的空格。@Roko C,你是说ng trim吗?angularjs中是否有ng修剪?是的。好的@RokoC.Buljan,我会尝试感谢你@DTing的解释答案,我在我的程序中尝试过,结果是字符串前面没有空格,你的答案是正确的。再次感谢。戴丁,请再帮我一次