conker87 Posted April 4, 2008 Share Posted April 4, 2008 As an absolute beginner using regular expressions (and loathing them) I've hit a snag. I'm trying to validate a few fields that will be POST'd using eregi(), I've been looking on a few websites and they always seems to have variants of the code I need, but not the exact. I'm looking for a expression that will allow alphanumeric characters, commas, apostrophes, (semi)colons and the dash (-) and underscores. Can anyone be my hero and take a shot at this? - Si Quote Link to comment Share on other sites More sharing options...
effigy Posted April 4, 2008 Share Posted April 4, 2008 I recommend PREG: /\A[-\w';:,]+\z/i Quote Link to comment Share on other sites More sharing options...
bozebo Posted April 6, 2008 Share Posted April 6, 2008 OK, here is my regular expression for you to try: [a-z0-9,';_-]* I tested it at http://regexlib.com/RETester.aspx and it seems fine, Now I will go over it for you: the [ and ] show that everything in them matches one character (as the * means 0 or more of the last match) so, the characters you want to match are in there: a-z is a range of any lower case letter (but you are using eregi to ignore case). 0-9 is a range of any numeric characters. the comma is just a comma, likewise with the apstrophy and underscore. But the dash is the interesting one, it must go at the end otherwise it will look for a range of characters, escaping it didn't seem to work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.