Jump to content

Email Id Validation Script


subha rr

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...