Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Angularjs ng模式仅输入非必需输入中的数字_Angularjs_Regex - Fatal编程技术网

Angularjs ng模式仅输入非必需输入中的数字

Angularjs ng模式仅输入非必需输入中的数字,angularjs,regex,Angularjs,Regex,我有一个输入文本不是必需的,我想只对数字字符使用ng模式,但当我提交表单时,输入无效。为什么? <input type="text" ng-model="price" format="currency" ng-pattern="/^[0-9]*$/"> 在JSFIDLE中,插入产品而不输入价格并提交: ps:我无法更改输入的类型 尝试使用/^[0-9]+$/+符号用于接受一个或多个数字。查看这是否有帮助 var-app=angular.module('demo',[]);

我有一个输入文本不是必需的,我想只对数字字符使用ng模式,但当我提交表单时,输入无效。为什么?

<input type="text" ng-model="price" format="currency" ng-pattern="/^[0-9]*$/">

在JSFIDLE中,插入产品而不输入价格并提交:


ps:我无法更改输入的类型

尝试使用
/^[0-9]+$/
+符号用于接受一个或多个数字。

查看这是否有帮助

var-app=angular.module('demo',[]);
应用程序控制器('MainCtrl',函数($scope){
$scope.price='';
$scope.seeResults=函数(){
console.log($scope.price);
};
});

价格应该是整数
提交

您的意思是键入一个数字并提交,然后出现错误吗?不,我有一个包含5个输入的表单,只需要一个(ng model=“productCode”),但当我汇总时,价格输入有“ng invalid pattern”类,我无法继续。由于regex模式没有问题,问题与代码有关。如果您需要帮助,请发布它(也欢迎任何指向小提琴的链接)。。它在那里工作,请参见我添加的JSFIDLE