[thelist] [regexp] I'm lost

Mike Migurski mike-evolt at teczno.com
Thu Jul 17 23:31:08 CDT 2003


>Thanks Paul after a bit of fudging, the following function seems to be
>working (I have to allow '$' as the company we are developing for insists
>on having text and dollar amounts in their 'fees' component)
>
># now check for alpha, numeric, spaces, hyphens, dollar signs,
>underscores and brackets
>        if(eregi('^[_\.\,a-zA-Z0-9 ()$-]+$', $value))

I generally prefer to use the 'preg' functions, because they more closely
emulate the perl regexp's i first learned -- not sure how this might work
with 'ereg', but the shorthand \w (word character) is equivalent to
[_A-Za-z0-9], and likewise \W is equivalent to anything not in that set.
Other shorthands provided include \s (space character), \S (not a space
character), \d (digit), and \D (not a digit).

So, yours might be rewritten as preg_match('^/[\w\(\) \$-]+$/', $value)

---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca            http://mike.teczno.com/contact.html



More information about the thelist mailing list