HOW TO VALIDATE A PHONE NUMBER IN ANGULARJS

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 710  View(s)
Ratings:
Rate this:
we want to Validate a Phone Number in AngularJS. please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to Validate a Phone Number in AngularJS

    @{

    Layout = null;

    }

    <!DOCTYPE html>

    <html>

    <head>

    <title>Forum</title>

    <meta name="viewport" content="width=device-width" />

    <script src="~/Scripts/jquery-1.9.1.js"></script>

    <script src="~/Scripts/angular.js"></script>

    <style>

    .error {

    color: red;

    }

    </style>

    <script>

    var app = angular.module('myApp', []);

    app.controller('mainCtrl', function ($scope) {

    $scope.phoneNumbr = /^\+?\d{2}[- ]?\d{3}[- ]?\d{5}$/;

    });

    </script>

    </head>

    <body ng-app="myApp">

    <ng-form name="myForm" ng-controller="mainCtrl">

    <div><b>Enter your Phone No:</b></div>

    <div>

    <input type="text" placeholder="+91-xxx-xxxxx" name="phone" ng-pattern="phoneNumbr" ng-model="phone" />

    <br><span class="error" ng-show="myForm.phone.$error.pattern">Please Enter vailid </span>

    </div>

    </ng-form>

    </body>

    </html>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!