Javascript 使用正则表达式验证Angular中的表单字段

Javascript 使用正则表达式验证Angular中的表单字段,javascript,angularjs,regex,angularjs-forms,Javascript,Angularjs,Regex,Angularjs Forms,我在跟踪这条消息,但它对我不起作用。有什么不对劲吗?我需要验证手机是否需要,是否符合+4400000000(加上信号和数字,没有空格,加上数字后才有数字)等国际标准 我的代码是 .controller('ModalInstanceChangeDetailsCtrl', function ($scope, $rootScope, $uibModalInstance, items) { $scope.rxMobile = '^\+[1-9]{1}[0-9]{3,14}$'; } <

我在跟踪这条消息,但它对我不起作用。有什么不对劲吗?我需要验证手机是否需要,是否符合+4400000000(加上信号和数字,没有空格,加上数字后才有数字)等国际标准

我的代码是

.controller('ModalInstanceChangeDetailsCtrl', function ($scope, $rootScope,  $uibModalInstance, items) {
    $scope.rxMobile = '^\+[1-9]{1}[0-9]{3,14}$';
}

<form name="form">
<div class="form-group">
        <label>Mobile number</label><label class="fieldError" ng-show="form.mobile.$error.required || !form.mobile.$valid">This field is required and must use International format, ex: +440000000000</label>
        <input ng-pattern="rxMobile" required ng-model="mobile" name="mobile" type="text" class="form-control">
 </div>
</form>
.controller('ModalInstanceChangeDetailsCtrl',函数($scope、$rootScope、$uibModalInstance,items){
$scope.rxMobile='^\+[1-9]{1}[0-9]{3,14}$';
}
手机号码此字段为必填字段,必须使用国际格式,例如:+440000000000
有什么建议吗?

使用此正则表达式验证国际标准电话号码:


$scope.rxMobile='^\\\+\\d{10}\\b';

使用正则表达式验证电话号码

+[\d]{10}$


好吧,我发现了问题所在

 $scope.rxMobile = /^\+[1-9]{1}[0-9]{3,14}$/;

如果我不加引号地将其括起来,它是有效的。

SyntaxError:无效的正则表达式:/^^+d{10}$/:在新的RegExp()中没有要重复的内容--$scope.rxMobile=“^\+\d{10}\b”@MarcoJr check edit