kabucek Posted May 13, 2009 Share Posted May 13, 2009 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 https://forums.phpfreaks.com/topic/157986-add-word-none-to-zip-in-validation/ Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Add another case. Link to comment https://forums.phpfreaks.com/topic/157986-add-word-none-to-zip-in-validation/#findComment-833330 Share on other sites More sharing options...
kabucek Posted May 13, 2009 Author Share Posted May 13, 2009 I tried those, but with no result: case '11': $pattern="^NONE$"; $emailTest=ereg($pattern, $inString); if (!$emailTest) { appendError("MUST BE NONE"); } break; case '13': $pattern="^[[:n:]][[:]][[:n:]][[:e:]]$"; $emailTest=ereg($pattern, $inString); if (!$emailTest) { appendError("MUST BE NONE"); } break; case '15': $pattern='#^(?:[\w-]+ ?)*$#'; $emailTest=ereg($pattern, $inString); if (!$emailTest) { appendError("MUST BE NONE"); } break; Link to comment https://forums.phpfreaks.com/topic/157986-add-word-none-to-zip-in-validation/#findComment-833332 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Well "NONE" has length of 4, so I have no idea what case '11' does. I only suggested add another case because I couldn't see what the code is doing. So, if you want, add case 4 and check if the string is equal to NONE. Then do something.... Link to comment https://forums.phpfreaks.com/topic/157986-add-word-none-to-zip-in-validation/#findComment-833333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.