[英]ng-pattern can only applied on input type text?
This is a really simple example: 这是一个非常简单的示例:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<script data-semver="1.2.11" src="http://code.angularjs.org/1.2.11/angular.js" data-require="angular.js@1.2.x"></script>
</head>
<body>
<form name="myForm">
<div>
<input type="number" name="number" ng-model="num" ng-pattern="/^\d+$/"/>
<br>error: {{ myForm.number.$error }}
</div>
<div>
<input type="text" name="text" ng-model="text" ng-pattern="/^\d+$/"/>
<br>error: {{ myForm.text.$error }}
</div>
</form>
<script type="text/javascript" charset="utf-8">
angular.module('myApp', []);
</script>
</body>
</html>
With both using the same ng-pattern
, only the one with input type text
work. 两者都使用相同的
ng-pattern
,只有输入类型为text
那个才有效。 Am I missing something here? 我在这里想念什么吗?
The HTML5's number
type is not currently supported by AngularJS. AngularJS当前不支持HTML5的
number
类型。 If you put required
directive in the input control, the validation will be triggered, and you can get the status from myForm.number.$valid
. 如果在输入控件中放置了
required
指令,则将触发验证,并且可以从myForm.number.$valid
获取状态。 Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.