Forum Moderators: open

Message Too Old, No Replies

check email validity

         

ft109

12:40 pm on Jul 31, 2008 (gmt 0)

10+ Year Member



can any one give me the code, how to check the validity of an email id at the client side itself using javascript.

gergoe

12:48 pm on Jul 31, 2008 (gmt 0)

10+ Year Member



Try this Google search [google.com], there are plenty of script to choose from. However note that while the test@example.com is a valid email address, the following are valid too:
  • test@any.host.example.com
  • test address <test@example.com>
  • 'test@example.com' <test@example.com>
  • <test@example.com>
  • test@72.3.232.139 - although this hardly happens
Consider this when choosing a script.

janharders

12:52 pm on Jul 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



while not being perfect, I've used
var filter=/^([a-zA-Z0-9\-\.\_]+)(\@)([a-zA-Z0-9\-\.]+)(\.)([a-zA-Z]{2,8})$/i;
if(filter.test(email))
{
// email valid, proceed
}
else
{
alert("Email invalid");
}

though you might want to make server side checks, checking if the domain has a valid mx etc, using you perl you could just try Email::Valid ( [search.cpan.org...] )

ft109

1:35 pm on Jul 31, 2008 (gmt 0)

10+ Year Member



thanks.
But here we are just checking whether the email is valid or not.
Can we check existence of the email id?

janharders

1:55 pm on Jul 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



email id? you mean if that alias actually exists on the mx? you can't on client side and on server side you might, but results are not 100% sure.

gergoe

2:46 pm on Jul 31, 2008 (gmt 0)

10+ Year Member



Far below 100%. If you want to be sure that an email address really exists is that you send an email to that address which needs to be confirmed. But this indeed must be done on the server, not on the client-side, using JavaScript. With JavaScript you can only check the syntax of the email address.

[edit]typo[/edit]

janharders

3:02 pm on Jul 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Far below 100%.

true. we use it to check on one site and, if checks say, the email is valid syntax but is rejected by the server, we tell the user but let him chose to say "I'm sure, go with it", not reject his adress because of our results.

btw: we were able to decrease non-activated registrations by 50% by just having user retype their email-adress and see if it matches. unbelievable, how many people insert typos anywhere in their email. from logs, I saw that some people didn't understand they'd have to submit a domain-name, just providing an alias. Now, I could follow that thought if it were AOL-users with their screen name being all they need for IM etc, but this was from users accross the board.