Regular expression for validating email address in javascript

06 Jan

Here we will learn what is ng-pattern directive in angularjs, how to use ng-pattern to validate form controls in angularjs, implement number, email validations with ng-pattern using regular expressions in angularjs applications with example In angularjs ng-pattern is used to validate input text controls with the help of regular expressions.The ng-pattern directive returns true if input text is validated as per expression otherwise it returns false.But what if I told you there were a way to determine whether or not an email is valid without resorting to regular expressions at all? The activation email is a practice that’s been in use for years, but it’s often paired with complex validations that the email is formatted correctly.It’s surprisingly easy, and you’re probably already doing it anyway. If you’re going to send an activation email to users, why bother using a gigantic regular expression?This is to verify that I actually own that email address before my account is activated.

I think Regex is only good for a rudimentary validation.

Here we will check whether user entered number and prevent form submission if validation fail for ng-pattern in angularjs application. Here we will check whether user entered number or not and check how many characters entered in textbox based on that validation result we will prevent form submission in angularjs.

We used other properties like $dirty, pattern for form validations.

I needed a simple email address validation in Java Script that caught obvious typos.

I didn’t really want to use a Regex because I wanted the code to be easy to understand when someone came to read it later, I knew whoever reading would know Java Script but wasn’t sure if they would know regexes that well.