Jump to content

Javascript Regexp For Email Verification


shadowayex
 Share

Recommended Posts

I've used PHP regular expressions before, and I've seen email verification done with them before. I'm trying to accomplish a similar effect browser-side.I think I have something, but I want opinions to make sure that I've got something good.I started with this:

var email = document.getElementById("email").value;var regexp = new RegExp(".+@.+\\..+");if(email.search(regexp) == -1){	alert("fail");}else{	alert("pass");}

That searched to make sure that @something.something existed in the email address. But that allowed email addresses like m@m.m to pass. So I kicked it up a notch. I've only seen the .somethings to be as short as 2 characters (.tv) and as long as 5 (.com.au). So I editted to to take a minimal of 2 characters after the dot:

var regexp = new RegExp(".+@.+\\...+);

But users could still put m@m.mm or something like that. I'm thinkng that's the best I can do and if users don't put a real email address then so be it.I plan on setting up a mail server and using PHP's mail() feature for email verification (make them click a link to activate the account and whatnot). Is this the best I can do? Or is there more browser-side tests that can be done?Edit: Fixing minor mistakes

Edited by ragae
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...