Once you have an HTML form up and running, you will often want to make sure that all the important fields are filled in.
For example, if you are going to send an email confirmation letter, the email address should be included in the form fields, and it should be an email address that works.
If we have passed the two tests, then else block in lines 11-14 gets executed.
An alert tells the user that he or she has done a good job and the function returns a true value so that you can continue with the form submission.
If you want to validate email addresses entered into your form but avoid complicated tinkering and scripts, HTML5 lets you rely on the browser — without effort, and without turning to Java Script.
Browsers that do not recognize type="email" should (and, as far as one can tell, all will) treat the input field like an ordinary type="text" field.
In this article, I am sharing some useful cross browsers regular expression patterns for validating email address with java script and jquery.
Below is simple regular expression to validate an email address. In this article I try to explain, how you can validate different-different email address acc. I hope after reading this article you will be able to use this trick in your code.
This method accepts regex expressions as arguments to check the string and returns the position of the specified value in the string or a -1 if no match was found.
I have borrowed the regex for verifying the correct email format from a different site. Please note that I have removed the action attribute because this is only a demo and we are only concerned with the client-side verification of the Java Script function.
Nothing exciting here except in line 6 where the on Click event is triggered when the user clicks on the button.
I would like to have feedback from my blog readers.
Please post your feedback, question, or comments about this article.