Advanced Search

Results 1 to 3 of 3

Thread: Can someone explain this RegEx?

  1. #1
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default Can someone explain this RegEx?

    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:

    PHP Code:
    preg_match('/^[^0-9][A-z0-9_-]+[@][A-z0-9_-]+([.][A-z0-9_-]+)*[.][A-z]{2,4}$/',$email
    Thanks

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    ^ - 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

  3. The Following User Says Thank You to techietim For This Useful Post:

    Schmoopy (04-14-2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Great, thanks for the explanation.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •