eregi not working as expected

Hello -

I have the code below

 
 if(!eregi("^([0-9a-z-])+$", $subaddr1)){
            $custerror->c_error("session.php", "430","Addr1 is not alphanumeric");
            $form->setError($field, "* Address1 not alphanumeric");
}
if  I set $subaddr1= '4404 Normandy Ave'

the if statement evaulates to true and executes the error functions

Why?





jerrylmclaughlinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
what about this:
if(eregi("^([0-9a-z ])+", $subaddr1)){
            $custerror->c_error("session.php", "430","Addr1 is not alphanumeric");
            $form->setError($field, "* Address1 not alphanumeric");
}
0
tolgaongCommented:
if (!eregi('^([a-z0-9[:space:]]+)$', $subaddr1)) {
$custerror->c_error("session.php", "430","Addr1 is not alphanumeric");
            $form->setError($field, "* Address1 not alphanumeric");      
      }
0
ixtiCommented:
if(!eregi("^([\w[:space:]])+$", $subaddr1)){
            $custerror->c_error("session.php", "430","Addr1 is not alphanumeric");
            $form->setError($field, "* Address1 not alphanumeric");
}

or

if(!eregi("^([\w\s])+$", $subaddr1)){
            $custerror->c_error("session.php", "430","Addr1 is not alphanumeric");
            $form->setError($field, "* Address1 not alphanumeric");
}
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

ixtiCommented:
Oh! Sorry! This:

--------------------------------------------------------------------------------------------
if(eregi("^([\w[:space:]])+$", $subaddr1)){
            $custerror->c_error("session.php", "430","Addr1 is not alphanumeric");
            $form->setError($field, "* Address1 not alphanumeric");
}
--------------------------------------------------------------------------------------------

or this:

--------------------------------------------------------------------------------------------
if(eregi("^([\w\s])+$", $subaddr1)){
            $custerror->c_error("session.php", "430","Addr1 is not alphanumeric");
            $form->setError($field, "* Address1 not alphanumeric");
}
--------------------------------------------------------------------------------------------
0
jerrylmclaughlinAuthor Commented:
I will try these solutions, but know one answered my question. Why isn't that simple pattern in eregi not working?

It should work as is?
0
Georgiana GligorCTO / OwnerCommented:
It's because you have spaces inside your string, and you only look after characters from the alphabet and numbers.
Look at the \s occurences in the examples given by the previous posters, which do exactly this: include the whitespaces in your regular expression.

Cheers,
  GB
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jerrylmclaughlinAuthor Commented:
Thank you tolagong and gicutza_cj

Angel III yours did not work, I assuming its due to the missing ! in front of the eregi

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.