View Full Version : Can someone explain this RegEx?
Schmoopy
04-14-2009, 10:08 PM
Hey, I have the following regex pattern to validate emails but I don't really understand it. Anyone who can explain it to me in basic terms? I've only just started with this really:
preg_match('/^[^0-9][A-z0-9_-]+[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,4}$/',$email)
Thanks :)
techietim
04-14-2009, 10:59 PM
^ - Start of the string
[^0-9] - any single character other then 0-9
[A-z0-9_-]+ - any alphanumeric, underscore or dash 1 or more times
[@] - the @ sign
[A-z0-9_-]+ - (same as 2 up)
([.][A-z0-9_-]+)* - A period followed by more that 1 alphanumeric, dash, or underscore character (this whole pattern can occur 0 or more times [subdomains])
[.] - A dot
[A-z]{2,4} - the alpha TLD, 2-4 characters in length
$ - end of the string
Schmoopy
04-14-2009, 11:09 PM
Great, thanks for the explanation.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.