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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.