Data Validation

Michael Fowler wolfm at pobox.alaska.net
Thu Jan 27 16:05:23 CST 2000


On Thu, Jan 27, 2000 at 09:01:45AM -0900, corliss at alaskapm.org wrote:
> Greetings:
> 
> I was recently talking to some people off list about using regexes for data
> validation.  I thought this was a good topic for the list, too, though, so I'm
> asking for your thoughts:  what are your favourite regexes to use for common
> data types?
> 
> Here's a few that I use often:
> 
> 	e-mail:  /^[\w\.]+\@[\w\.-]+\.\w{2,3}$/
> 	telephone:  /^(\(?\d{3}\)?[\s-]?)?\d{3}[-\s]?\d{4}$/
> 	zip code:  /^\d{5}(-\d{4})?/
> 
> Anyone have any other nifty ones to share?

Regexen to get the unquoted part out of a quoted string.  Backwacking the
quote character, and backwacking the backwack are dealt with:

single-quoted string: '((?:\\\\|\\'|[^\\']+)*)'
double-quoted string: "((?:\\\\|\\"|[^\\"]+)*)"

It'd be nice if I could combine them, using \1, but as far as I
can tell, \1 can't be used in a character class, and that negated character
class is a must.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--
=================================================
Mailing list info:  If at any time you wish to (un|re)subscribe to
the list send the request to majordomo at hfb.pm.org.  All requests
should be in the body, and look like such
                  subscribe anchorage-pm-list
                  unsubscribe anchorage-pm-list



More information about the Anchorage-pm mailing list