Jump to content

add NONE field in zip validation


Recommended Posts

hi @LL,

we are using simple code for validation in zip, but now we want to be able to type the word

"NONE" also.

How this code can be modified to do that?

case 'zip':

if ($inString=='') { appendError("Required Field"); }

else {

$length=strlen($inString);

switch($length)

{

default:

appendError("Must be 5 digit zip '00000', or zip+4 '00000-0000' or 'NONE'");

break;

case '5':

$pattern="^[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]$";

$emailTest=ereg($pattern, $inString);

if (!$emailTest) { appendError("Only numbers allowed in zip"); }

break;

case '7':

$pattern="^[[:digit:]][[:digit:]][[:digit:]][[:space:]][[:digit:]][[:digit:]][[:digit:]]$";

$emailTest=ereg($pattern, $inString);

if (!$emailTest) { appendError("Canadian postal codes must be three digits, one space, three digits"); }

break;

case '10':

$pattern="^[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]-[[:digit:]][[:digit:]][[:digit:]][[:digit:]]$";

$emailTest=ereg($pattern, $inString);

if (!$emailTest) { appendError("Not a valid Zip+4 format"); }

break;

Thanks

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...