subha rr 0 Posted January 16, 2009 Report Share Posted January 16, 2009 Hi.......I need to validate the email address when submit the form using java script. When I enter one email address i have to validate the mail id. I unable to validateHow can i validate the email address when i click on the form .Pls help me..Regards,Subha Quote Link to post Share on other sites
boen_robot 107 Posted January 16, 2009 Report Share Posted January 16, 2009 You should validate the email on the server, not the client. If you truly submit the form with JavaScript (AJAX style), it should be a snap to return an error back to JavaScript on failure or do something else on success.The means to validate the mail on the server vary depending on your server language of choise. In PHP, the easiest and most catch-all way of doing it is with the filter extension (built into PHP5), like so: if (is_bool(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL))) {//mail is invalid. Error handling goes here.}else {//mail is valid. Send the message from here} Quote Link to post Share on other sites
deepshah 0 Posted January 24, 2009 Report Share Posted January 24, 2009 if you want to validate email id using javascript, use following function.It's working perfect.function validateEmail(email_id){ var emailId=email_id; var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i if (!filter.test(emailId)) { return false; else return true;} Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.