add word NONE to zip in validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kabucek
Forum Commoner
Posts: 50
Joined: Thu Sep 04, 2008 2:20 pm

add word NONE to zip in validation

Post by kabucek »

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?

Code: Select all

 
    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
Last edited by Benjamin on Wed May 13, 2009 1:12 pm, edited 1 time in total.
Reason: Added [code=php] tags.
Post Reply