Validate phone number using angular js

前端 未结 9 553
情歌与酒
情歌与酒 2020-12-03 00:13

Want to set phone-number to 10 digits, How can I do this using Angular js.

This is what I have tried:



        
9条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 00:32

    You can also use ng-pattern and I feel that will be a best practice. Similarly try to use ng-message. Please look the ng-pattern attribute on the following html. The code snippet is partial but hope you understand it.

    angular.module('myApp', ['ngMessages']);
    angular.module("myApp.controllers",[]).controller("registerCtrl", function($scope, Client) {
      $scope.ph_numbr = /^(\+?(\d{1}|\d{2}|\d{3})[- ]?)?\d{3}[- ]?\d{3}[- ]?\d{4}$/;
    });
    

    Phone number is required.

    Phone number is invalid.

提交回复
热议问题