By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,954 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,954 IT Pros & Developers. It's quick & easy.

eregi help?

P: n/a
God, I have read every comment in php.net eregi and Google searched,
and I have tried so many different attempts...this is the closest I've
gotten to verify a variable contains only:
alphanumerics, spaces, underscore, hyphen, period, apostrophe

if(eregi("^[a-z0-9 _.-]+$", $value))
{
return true;
}

Problem is, when I try to add anything else, like a comma or
apostrophe, it fails:

if(eregi("^[a-z0-9 _.-\\'\,]+$", $value))

and I can't get it to make sure the first character only is
alphanumeric:

if(eregi("^([a-z0-9])[a-z0-9 _.-\\'\,]+$", $value))

what am I missing? What am I doing wrong that I can simply add a comma
and apostrophe to the list of OK characters, and make sure only a num'
or letter is first? I've found A LOT of examples to verify e-mail
addresses...but all the + and brackets and whatnot confuse the heck out
of me, trying to interpret what does what in the order of expressions.

Thanks for any help.

Sep 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ne**@celticbear.com wrote:
if(eregi("^[a-z0-9 _.-\\'\,]+$", $value))


The hyphen is a meta character here, forming part of a character
range. To be taken literally it must go first or last in the class,
or after the first endpoint in a range.

--
Jock
Sep 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.