Home > DeveloperSection > Forums > How to Validate a Phone Number in AngularJS
Ankit Singh

Total Post:341

Points:2389
Posted on    February-28-2016 10:30 PM

 Angular JS Angular JS 
Ratings:


 1 Reply(s)
 317  View(s)
Rate this:
we want to Validate a Phone Number in AngularJS. please help me.


aditya kumar Patel

Total Post:246

Points:1752
Supported
Posted on    February-28-2016 10:32 PM

@{

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>


Don't want to miss updates? Please click the below button!

Follow MindStick