vcphp Posted April 17, 2007 Share Posted April 17, 2007 hi guys, I'm try validating one email input, like $email = "[email protected]"; and i make that, but i see one code in the web, i i don't understand one thing. what the difference between: $exp = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]+\.[a-z]{2,4}$"; and $exp2 = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$"; Here is the code that i can't understand *[a-z0-9_\-] Tks Link to comment https://forums.phpfreaks.com/topic/47399-ereg-stuff/ Share on other sites More sharing options...
Psycho Posted April 17, 2007 Share Posted April 17, 2007 That allows for an email addres with 1 or more sub-domains. The part before the asterisk (which is common to both expressions) allows for an alpha-numeric (plus '_' & '-') ending in a period. The asterisk means it can match the preceeding section 0 or multiple times. However, both expressions are wrong because of several reasons: - They do not allow upper case characters - They would allow the domain to begin with a period or have two periods in succession - They do not allow the plus sign ('+') in the username portion, which is a perfectly acceptable character in an email address Here is a long, but very comprehensive, regex expression for email addresses: ^([a-zA-Z0-9-_\+])+([\.]?[a-zA-Z0-9-_\+])*@([a-zA-Z0-9])+([\.-]?[a-zA-Z0-9])*\.([a-zA-Z]{2,})$ Link to comment https://forums.phpfreaks.com/topic/47399-ereg-stuff/#findComment-231315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.