Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ereg help with street names

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
CA
how do i validate the street name with the ereg code?

if (!ereg("[A-Za-z0-9\#\-\]+$",$street)){

with the $street="159 rouge forest cres"

but still having a problem

TIA Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
I think this is what you're looking for...
(note, I removed the !, and I added the ^, which anchors the regex to the beginning... (you already have the $ to anchor it to the end)).

Code:
if (ereg("^[A-Za-z0-9\#\-\]+$",$street)){ 
  echo "good";
} else {
  echo "bad";
}

-Rob
 
nope not working

if (ereg("^[A-Za-z0-9\#\-\.]+$",$street)){
echo "ok street";
}else{
$street="error";
echo "error str";
$errors=1;
}

what have i got wrong here Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
You neglected (as did I in my above example) to allow for spaces... just put a space after the period but before the bracket and you're good.

-Rob
 
perfect that got it...thx Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top