I have often seen entry level developers struggling with user input validation in AngularJS single page applications. In this post, I will give a quick but useful introduction of validations in AngularJS; consider this post as a base learning document from which you can do further learning.
Let’s start with an example as shown in the image below. You have a registration form with three fields with the following restrictions.
- Name : Required
- Email : Required and type Email
- Password : Required , type password and minimum length 6
We want to validate the rules mentioned above at the client side. There are two ways client side validation can be done in an AngularJS based single page application:
- Using the HTML5 validations
- Using the AngularJS validation directives
- A Combination of both
HTML5 validation
Here we’ve created the Add user form shown above using the mark up listed below:
Leave a Reply