| |
|
Form Validation
From AngularJS we can validate input data by user. Its offers client side form validation. From AngularJS monitors state of form and input fields like input, textarea and select. And helps you to get the current state to the user. From AngularJS will holds information about if they have been touched or modified or not. We can use standard HTML5 attributes to validate user input. We can also make custimzation validation.
As we all know the only client side validation is not enough to fully secure user input we will also need server side validation.
Now below have some validation with examples:-
Required Field
Here we will use HTML5 attribute required to specify that input field must have some values. As below example:-
E-mail
Here we use HTML5 type email to specify that the value must be an email. And below is the example:-
Now we read most important aspects in form state and input state
Form State and Input State
AngularJS constantly update the state of both the form and Input fields.
Below are different Input fields have the following states:-
(1)$untouched This will happen when field has not been touched yet
(2)$touched This will happen when field has been touched
(3)$pristine This will happen when field has not been modified yet
(4)$dirty This will happen when field has been modified
(5)$invalid This will happen when field content is not valid
(6)$valid This will happen when field content is valid
All of above properties of input field either true or false.
Below are different Forms states:-
(1)$pristine When No fields have been modified yet
(2)$dirty when One or more have been modified
(3)$invalid When form content is not valid
(4)$valid when form content is valid
(5)$submitted when form is submitted
All of above properties either true or false.
From above properties we have use one touched example which will helps you to understand
| |
|
|
|
|