How to use email validation in Java script? For example User can't enter invalid email address...Please explain..
in a nutshell... your form or whatever will have an email field. the form submit action is handed to a javascript function that reads the text typed into the field and runs a regular expression test. that's basically matching it against a pre-defined ruleset of what an email is supposed to look like as defined by RFCs and conventions. based upon the outcome, it can be either valid or invalid. if valid, you can continue and allow the submission (do nothing) or you can print an error near the field / alert / empty the text and then return false (or stop the event propagation) - effectively cancelling the submit until the is-Valid-Email check is true. here is a sample function that can test a string against an email format: String.prototype.isEmail = function() { var validEmailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return this.match(validEmailRegex); }; // example use: var email = "joe@blogs.com"; // or pass on a value from an input etc. if (email.isEmail()) { alert("your email is good"); } else { alert("please check your email is valid"); } Code (javascript): i hope this make sense - here it is in action, testing against known valid emails that most simpler regex checks may fail to accept: http://fragged.org/dev/email_test.php regards,