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:
2 responses to “Validating User Input on a Form in Angular JS”
[…] Validating User Input on a Form in Angular JS and How to work with the Ignite UI Chart in an AngularJS application and How to Enable CORS in the ASP.NET Web API (Dhananjay Kumar) […]
Hi DJ,
Finally Learning Angular JS from you through your blog. Proud of you and lots of love and respect.