subha rr Posted January 16, 2009 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 Link to comment Share on other sites More sharing options...
boen_robot Posted January 16, 2009 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} Link to comment Share on other sites More sharing options...
deepshah Posted January 24, 2009 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;} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.