Jump to content

Punctuation in eregi


conker87

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/99546-punctuation-in-eregi/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/99546-punctuation-in-eregi/#findComment-510468
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.