angularjs has built-in helper to validate form in client side, here is how you can use it.
1 2 3 4 5 6 7 8 9 10
Notice that the name in form and input fields which is used as referenced when pass form object and check whether the field is valid.
$dirty use to check whether the field value changed and $invalid to check whether the field in valid, these two methods are useful to show errors message for the fields.
1 2 3 4 5 6 7 8 9
In controller, we can use the form object to check whether the form is valid before submit data to server.
There’s a lot of ways that you can valid your input fields.
- ng-pattern (use regular expression for validation)
- email ( if you specify email as type )
- number ( if you specify number as type )
- url ( if you specify url as type )
- custom validation