angularjs url validation

angularjs url validation

This code sample are used to validate a web URL address which are given below.

Table of Contents.
  1. input type is equal to URL [type="url"].
  2. This is used a required element.
  3. This is not a valid URL.
  4. This validation is working on input keyup.
Example code as given below.

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

      app.controller('mainCtrl', function ($scope) {
          $scope.webURL = '';
<body ng-app="myApp">
  <ng-form name="myForm" ng-controller="mainCtrl">
      <div>URL :</div>
        <input type="url" name="webURL" ng-model="webURL" required>
        <span class="error" ng-show="myForm.webURL.$error.required">Required.</span>
        <span class="error" ng-show="myForm.webURL.$error.url">Not valid url.</span>


The result look like below image.


Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog -
My Books - Book 1 and Book 2

angularjs url validation angularjs url validation Reviewed by Anil Singh on 11:03 AM Rating: (5) Powered by Blogger.