Validation in AngularJS

Sample Code:

<!DOCTYPE html>
<script src= ""></script>  
<h2>Validation Example</h2>
<form ng-app="" name="myForm" novalidate ng-init = "age = 9; email = ''; user = 'user'">
<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="number" name="age" ng-model="age" required>
<span style="color:red" ng-show="myForm.age.$dirty && myForm.age.$invalid">
<span ng-show="myForm.age.$error.required">Age is required.</span>
<span ng-show="myForm.age.$error.number">Invalid Age.</span>
<input type="submit" ng-disabled="myForm.user.$dirty && myForm.user.$invalid ||$dirty &&$invalid || myForm.age.$dirty && myForm.age.$invalid">



No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit