View Single Post
Old Jun 29th, 2006, 1:39 AM   #1
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
Email validating regex

I know this was discussed in another thread, but that one's been dead and I thought it seemed peaceful that way. Anyways, I was writing a regex for email addresses and came across a little question:

On this page it has the following language for domain names:
Quote:
<domain> ::= <subdomain> | " "

<subdomain> ::= <label> | <subdomain> "." <label>

<label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]

<ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>

<let-dig-hyp> ::= <let-dig> | "-"

<let-dig> ::= <letter> | <digit>

<letter> ::= any one of the 52 alphabetic characters A through Z in
upper case and a through z in lower case

<digit> ::= any one of the ten digits 0 through 9
does the spec for label mean [letter][ldh-str]?[let-dig] or [letter]([ldh-str]*[let-dig])* or something else? I went for the 2nd one, but wasn't sure as I'd not seen the [] notation used as it was in the quoted form.

And for those who care, my regex (which is not perfect yet) is:
^[!#$%\'*+/=?^_`{|}~A-Za-z0-9-]([!#$%\'*+/=?^_`{|}~\.A-Za-z0-9-]*[!#$%\'*+/=?^_`{|}~A-Za-z0-9-])@([A-Za-z]([A-Za-z0-9-]*[A-Za-z0-9])*\.)*[A-Za-z]([A-Za-z0-9-]*[A-Za-z0-9])?$

Last edited by Jimbo; Jun 29th, 2006 at 2:01 AM.
Jimbo is offline   Reply With Quote