Created
January 6, 2016 09:02
-
-
Save shiftenterdev/482f211933afb3e40334 to your computer and use it in GitHub Desktop.
Angular Form Validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Validation</title> | |
<link rel="stylesheet" href="https://bootswatch.com/paper/bootstrap.min.css"> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> | |
</head> | |
<body class="container"> | |
<div class="panel panel-primary"> | |
<div class="panel-heading"> | |
<h3 class="panel-title">User Registration by Angular</h3> | |
</div> | |
<div class="panel-body"> | |
<form class="form-horizontal" ng-app="myApp" ng-controller="validateCtrl" name="myForm" novalidate> | |
<fieldset> | |
<legend>Form Field</legend> | |
<div class="form-group"> | |
<label for="user" class="col-lg-2 control-label">User</label> | |
<div class="col-lg-10"> | |
<input class="form-control" id="user" name="user" ng-model="user" | |
minlength="5" required placeholder="Username"> | |
<div class="help-block" style="color:red" ng-show="myForm.user.$dirty && myForm.user.$invalid"> | |
<span ng-show="myForm.user.$error.required">Username is required.</span> | |
<span ng-show="myForm.user.$error.minlength">Username is Short.</span> | |
</div> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="inputEmail" class="col-lg-2 control-label">Email</label> | |
<div class="col-lg-10"> | |
<input class="form-control" id="inputEmail" name="email" | |
placeholder="Email" type="email" ng-model="email" | |
ng-pattern="/^[a-z]+[a-z0-9._]+@[a-z]+\.[a-z.]{2,5}$/" required> | |
<div class="help-block" style="color:red" ng-show="myForm.email.$dirty && myForm.email.$invalid"> | |
<span ng-show="myForm.email.$error.required">Email is required.</span> | |
<span ng-show="myForm.email.$error.pattern">Invalid Email.</span> | |
</div> | |
</div> | |
</div> | |
<div class="form-group"> | |
<div class="col-lg-10 col-lg-offset-2"> | |
<button type="submit" class="btn btn-primary" ng-disabled="myForm.user.$dirty && myForm.user.$invalid ||myForm.email.$dirty && myForm.email.$invalid || myForm.user.$pristine">Submit</button> | |
</div> | |
</div> | |
</fieldset> | |
</form> | |
</div> | |
</div> | |
<script> | |
var app = angular.module('myApp', []); | |
app.controller('validateCtrl', function ($scope) { | |
$scope.user = ''; | |
$scope.email = ''; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Angular Form Validation