• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

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?





0
jerrylmclaughlin
Asked:
jerrylmclaughlin
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 GligorCommented:
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
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now