Regular Expression Problem

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Why does [A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+ match matt.johnso#[email protected]

but not

matt.johnso#n@exam#ple.com

It allows special characters in the email name, but not in the domain name. I don't get it.

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Sorry, I'm retarded and don't know regular expressions from beans. Here's a better one for email I just found in my book

^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-zA-Z]{2,4}$

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Cool, thanks for this. I was groaning when I saw 'regular expressions', they're so powerful and yet so evil! Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.