Re: [SLUG] Standard Regular Expressions (REs)

From: Levi Bard (levi@bard.sytes.net)
Date: Mon Mar 24 2003 - 10:31:34 EST


>
> Does anyone know of a list of "standard REs" that one might use to
> validate the characters used in,
> for example, an e-mail address, a phone number (domestic or
> international), or a URL?
>
> We are looking for a list that folks have thought about. Probably not a
> list that strictly follows the
> RFCs, because my suspicion is that "reality" does not exactly follow the
> RFCs. Either the RFC is
> more or less strict than the implimentations which are commonly accepted
> (i.e. some standard).
>
> To give a more concrete example of what we are looking for, something
> like this
>
> social security number
> \d{3}-\d{2}-\d{4}
> phone number
> \(\d{3}\) (\d{3}-\d{4})
> e-mail
> [\w\.\-]+@[\w\.\-]+
>
> But notice, one of these messy characters, [~!@#$%^&*()_+=],
> may also be "allowed" in an e-mail address, so the REs just listed could
> be better.

I would definitely follow the RFC, and reject anything nonstandard.

For an email, I might use '[^ ]+@[^ ]+' , since characters like
underscores are definitely allowed. A phone number's more difficult,
since there are so many ways people delineate phone numbers. +011 83 44
55, 18135551212 1-(813) 555-1212,813.555.1212, and so on. Maybe the best
thing to do would be to extract the numeric characters from the string (it
sounds like you want to verify a string from a user or a text field), and
verify that there are at least 7 digits, and not more than a predetermined
maximum, 10 or 11(if the 1- is added) for a domestic number, I have no
idea for international.

Levi



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:12:15 EDT