AngularJS Validation

<!DOCTYPE html>
<script src=””></script>

<h2>Validation Example</h2>

<form ng-app=”myApp” ng-controller=”validateCtrl”
name=”myForm” novalidate>

<input type=”text” name=”user” ng-model=”user” required>
<span style=”color:red” ng-show=”myForm.user.$dirty && myForm.user.$invalid”>
<span ng-show=”myForm.user.$error.required”>Username is required.</span>

<input type=”email” name=”email” ng-model=”email” required>
<span style=”color:red” ng-show=”$dirty &&$invalid”>
<span ng-show=”$error.required”>Email is required.</span>
<span ng-show=”$”>Invalid email address.</span>

<input type=”submit”
ng-disabled=”myForm.user.$dirty && myForm.user.$invalid ||$dirty &&$invalid”>


var app = angular.module(‘myApp’, []);
app.controller(‘validateCtrl’, function($scope) {
$scope.user = ‘John Doe’;
$ = ‘’;


It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *