ProblemHelpPlease Posted March 17, 2009 Share Posted March 17, 2009 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 More sharing options...
jesh Posted March 17, 2009 Share Posted March 17, 2009 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 More sharing options...
ProblemHelpPlease Posted March 17, 2009 Author Share Posted March 17, 2009 Thanks, thats what I thought, I was just confused as to why _ was being allowed as well.Site looks helpful as well Link to comment Share on other sites More sharing options...
justsomeguy Posted March 17, 2009 Share Posted March 17, 2009 I believe the underscore is considered a word character. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted March 18, 2009 Author Share Posted March 18, 2009 I wondered if that was the case Mystery solved Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.