我正在遵循官方的角文档,但对我不起作用。怎么了?我需要验证是否需要手机并遵循国际标准(例如 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>
任何建议?
使用此 regex 验证国际标准电话号码:
$scope.rxMobile = '^\+\d{10}\b';
使用正则验证电话号码
[ d] {10} $
好吧,我发现了什么问题...
$scope.rxMobile = /^+[1-9]{1}[0-9]{3,14}$/;
如果我没有引号,则可以使用它。