jardane Posted April 18, 2010 Share Posted April 18, 2010 I have an input box for a zip code and i need error code to check if it contain 5 digits and contains only numbers. Link to comment https://forums.phpfreaks.com/topic/198932-error-checking-of-a-variables-length-and-if-its-numeric/ Share on other sites More sharing options...
litebearer Posted April 18, 2010 Share Posted April 18, 2010 look here http://roshanbh.com.np/2008/03/usa-zip-code-format-validation-php.html Link to comment https://forums.phpfreaks.com/topic/198932-error-checking-of-a-variables-length-and-if-its-numeric/#findComment-1044193 Share on other sites More sharing options...
SaMike Posted April 18, 2010 Share Posted April 18, 2010 strlen returns string's length and is_numeric checks if its numeric (who knew, right?) Example: <?php $string = "51245"; if(!is_numeric($string)) exit('Numbers only lol!'); if(strlen($string) != 5)) exit('5 numbers lol!'); ?> Link to comment https://forums.phpfreaks.com/topic/198932-error-checking-of-a-variables-length-and-if-its-numeric/#findComment-1044208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.