python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
angularjs phone number validation

AngularJs Phone Number Validation

This code sample are used to validate a phone number using ng-required, ng-pattern, ng-minlength and ng-maxlength which are given below in detail.

Table of Contents.
  1. input type is equal to text i.e. [type="text"].
  2. Used to required element.
  3. Used to ng-pattern attribute.
  4. Used to minlength and maxlength.
  5. place-holder control etc.. 
Example code as given below.

<!doctype html>
  <script src=""></script>
    .error {
      color: red;
      var app = angular.module('myApp', []);

      app.controller('mainCtrl', function ($scope) {
          $scope.phoneNumbr = /^\+?\d{2}[- ]?\d{3}[- ]?\d{5}$/;
<body ng-app="myApp">
  <ng-form name="myForm" ng-controller="mainCtrl">
    <div>Phone No. :</div>
      <input type="text" placeholder="+91-636-78658" name="phone" ng-pattern="phoneNumbr" ng-model="phone" />
      <span class="error" ng-show="$error.required">Required!</span>
      <span class="error" ng-show="$error.minlength">Phone no not less that 10 char.</span>
      <span class="error" ng-show="$error.maxlength">Phone no not more than 11 char.</span>
      <br><span class="error" ng-show="$error.pattern">Please match pattern [+91-036-78658 || 91-036-78658]</span>

The live demo example link


Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions