This code sample are used to validate a web URL address which are given below.
Table of Contents.
<!doctype html>
Table of Contents.
- input type is equal to URL [type="url"].
- This is used a required element.
- This is not a valid URL.
- This validation is working on input keyup.
<!doctype html>
<html>
<head>
<title>angularjs url validation</title>
<script src="http://code.angularjs.org/1.2.9/angular.min.js"></script>
<style>
.error {
color: red;
}
</style>
<script>
var app = angular.module('myApp', []);
app.controller('mainCtrl', function ($scope) {
$scope.webURL = '';
});
</script>
</head>
<body ng-app="myApp">
<ng-form name="myForm" ng-controller="mainCtrl">
<div>
<div>URL :</div>
<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>
</div>
</div>
</ng-form>
</body>
</html>
The result look like below image.