0

I'm following the official angular documentation , but it's not working for me. What could be wrong ? I need to validate if the mobile phone are required and following the international standard like +4400000000 (plus signal and numbers, no space, only numbers after the plus).

My code is....

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

Any suggestion ?

Marco Jr
  • 6,496
  • 11
  • 47
  • 86

3 Answers3

0

use this regex to validate international standard phone number :

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

m87
  • 4,445
  • 3
  • 16
  • 31
0

Use the regex to validate the phone number

+[\d]{10}$

0

Ok, I found what's wrong...

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

It's works if I enclose it without quotation.

Marco Jr
  • 6,496
  • 11
  • 47
  • 86