Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg_match()

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi. For some reason i am getting a parse error from the following line;

if (!preg_match("/[0-9a-z]([-_.+]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,}$/", $email) { error("The email you submitted is not in the correct format! This address will be used to contact you regarding your submission, and nothing else!"); }

Can anyone see a reason why?

Thanks

Andy
 
In Regular Expressions a dot (.) means any char, so when we want to represent the dot we must do \.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Hi. Where abouts are you refering to as the 'dots' ?

Thanks

Andy
 
if (!preg_match("/[0-9a-z]([-_\.+]?[0-9a-z])*\@[0-9a-z]([-\.]?[0-9a-z])*\.[a-z]{2,}$/", $email) { error("The email you submitted is not in the correct format! This address will be used to contact you regarding your submission, and nothing else!"); }
//Daniel
 
Still giving a parse error :(

Parse error: parse error in c:\program files\nusphere\apache\nsdocs\test\contact.php on line 147

any more ideas?

Thanks

Andy

BTW, im using the code daniel just provided above.
 
I think you might need to escape the -, like:
if (!preg_match("/[0-9a-z]([\-_\.+]?[0-9a-z])*\@[0-9a-z]([\-\.]?[0-9a-z])*\.[a-z]{2,}$/", $email) { error("The email you submitted is not in the correct format! This address will be used to contact you regarding your submission, and nothing else!"); }
//Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top