Jump to content

E-mail Validation Advice


ProblemHelpPlease
 Share

Recommended Posts

I am currently using the script below to validate e-mail addresses but it has a problem in that it won't allow certain charaters that can be used in the local part of email addresses like +

if (!/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(document.createaccount.email.value)){alert("Not a valid e-mail address");return false;}

I'm still getting used to using all the aspects of regular expressions (anyone know of a good advanced tutorial) and am not sure how to add the + or any other charater into the script.

Link to comment
Share on other sites

I am partial to this site regarding regular expressions:http://www.regular-expressions.info/As to how to match a "+", just put it inside the character class "[]". You're already searching for letters and digits (\w) and hypens (-), so, if you want to add "+" into the mix, modify your character class from "[\w-]" to "[\w+-]".

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...