form validation in angular is powerful,
A total of 5 verification information, $valid, $invalid, $pristine, $dirty, $error.
$valid-----When validation passes, true, false when not passed
$invalid----When the validation does not pass, true when passed.
True if the $pristine---is the initial value, false once the change has been made
$dirty---The value has been changed is true, the other is False
$error---Contains all the validation information, such as the following example, $error = {Required:false,minlength:false,pattern:false}. Which validation does not pass, its value is true.
The above five values can be obtained by using the name of the form, as follows:
<form novalidate name= "MyForm" >
<input type= "text" name= "MyText" ng-model= "text" Required ng-minlength= "5" ng-pattern= "/^[a-za-z]+$/" >
<div>{{Myform.mytext. $valid}}</div>
<div>{{Myform.mytext. $invalid}}</div>
<div>{{Myform.mytext. $pristine}}</div>
<div>{{Myform.mytext. $dirty}}</div>
<div>{{Myform.mytext. $error}}</div>
</form>
You can do some form validation with Ng-repeat filter $error, and so on
<script>var m1 = Angular.module (' myApp ', []); M1.controller (' Aaa ', [' $scope ', function ($scope) {$scope. Text = ' Hello '; $scope. Regtext = {regT: ' Default ', Reglist: [{name: ' Default ', text: ' Please enter the username '}, {name: ' Required ', text: ' cannot be empty '}, {name: ' pattern ', text: ' Only for Letters '}, {name: ' Pass ', text: ' √ '},], change:function (err) {Console.log (err); for (Var attr in err) {if (err[attr]==true) {$scope. Regtext.regt = attr; Return }} $scope. regtext.regt = ' pass '; } };}]); </script>
form validation in angular