Jump to content

problem with my regex


Stickybomb

Recommended Posts

ok i got all my regs, however for some reason some of them test fine with the tester on the RegExLib site, but are not working for my project, i am using the same data

 

here is the code im using

 

these are the reg values

 

$emailreg = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$";
$namereg = "^[A-Za-zÀ-ÖØ-öø-ÿ '\-\.]{1,22}$";
$address1reg = "^\d{1,5}\s[\w0-9][\sa-zA-Z0-9]*[aAvVeEsSrRdDtT]{2,3}\.?\s[nNsSeEwW][\.\s]?[nNsSeEwW][\.]?$";
$address2reg = "^p(ost)?[ |\.]*o(ffice)?[ |\.]*(box)?[ 0-9]*[^[a-z ]]*";
$zipreg = "(^\d{5}$)|(^\d{5}-\d{4}$)";
$phonereg = "^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$";
$statereg ="^((AL)|(AK)|(AS)|(AZ)|(AR)|(CA)|(CO)|(CT)|(DE)|(DC)|(FM)|(FL)|(GA)|(GU)|(HI)|(ID)|(IL)|(IN)|(IA)|(KS)|(KY)|(LA)|(ME)|(MH)|(MD)|(MA)|(MI)|(MN)|(MS)|(MO)|(MT)|(NE)|(NV)|(NH)|(NJ)|(NM)|(NY)|(NC)|(ND)|(MP)|(OH)|(OK)|(OR)|(PW)|(PA)|(PR)|(RI)|(SC)|(SD)|(TN)|(TX)|(UT)|(VT)|(VI)|(VA)|(WA)|(WV)|(WI)|(WY))$";

 

 

 

this is the code to test them

 

 //chnage case
$state = strtoupper($state);

//check size
if(strlen($_POST['chimney_pot_size']) > 2){$sizeflag=1; $size='';}
//check email
if(!eregi($emailreg, $email)) {
  $emailflag=1;
  $email='x';
}else{$email=$_POST['email'];}
//check name
if(!eregi($namereg, $name)) {
  $nameflag=1;
  $name='x';
}
//check address1
if(!eregi($address1reg, $address1)) {
  $address1='x';
}
//check address2
if(!eregi($address2reg, $address2)) {
  $address2='x';
}
//check city
if(!eregi($namereg, $city)) {
  $city='x';
}
//check state
if(!eregi($statereg, $state)) {
  $state='x';
}
//check zip
if(!eregi($zipreg, $zip)) {
  $zip='x';
}
//check phone
if(!eregi($phonereg, $phone)) {
  $phone='x';
}

 

i have it set to show an x if its not working

 

 

This is my test data

 

name=bob marley

address1=1234 newport rd. n.w.

address2=po box 1234

city=springfield

state=ca

zip=12345

telephone=(123)-456-7890

 

 

the results i am getting

 

name =bob marley

address1=x

address2=po box 1234

city=springfield

state=CA

zip=x

telephone=x

 

 

 

if anyone can help me with this or knows what it is im doing wrong it would help me out alot.

 

thks

 

stickybomb

Link to comment
Share on other sites

You're using ereg, not preg, so the shorthands do not work. I recommend switching to preg.

 

Also:

 

- The state should be checked with an array + in_array, not a regex.

- Unless your data can end with a new line, use \z instead of $.

- Keep in mind that \w includes an underscore (after you switch to preg).

- Unless you're capturing the data, use (?:...) instead of (...).

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.