AV1611 Posted June 1, 2012 Share Posted June 1, 2012 Ok, so I need a form to validate that the data entered was a 10 digit number ONLY. It must be a number and it must be 10 digits. if(!eregi("[0-9]{10}",$str)) echo "Invalid Serial Number"; Is this right? Link to comment https://forums.phpfreaks.com/topic/263495-verify-string/ Share on other sites More sharing options...
Mahngiel Posted June 1, 2012 Share Posted June 1, 2012 function.is-numeric.php function.strlen.php <?php $serial_no = $_POST['serial']; if( is_numeric($serial_no) && (strlen($serial_no) === 10) ) { do this } else { do this } ?> Link to comment https://forums.phpfreaks.com/topic/263495-verify-string/#findComment-1350347 Share on other sites More sharing options...
AV1611 Posted June 1, 2012 Author Share Posted June 1, 2012 fair enough... also I guess it's preg_match as the other is deprecated now... ...for my education, can someone tell me how to syntax the above with regex? Link to comment https://forums.phpfreaks.com/topic/263495-verify-string/#findComment-1350348 Share on other sites More sharing options...
requinix Posted June 1, 2012 Share Posted June 1, 2012 is_numeric() will accept real and negative numbers. Try ctype_digit instead. Your regex needed start-of-string and end-of-string anchors, otherwise it only checked if the input contained a 10-digit number. /^[0-9]{10}$/ Link to comment https://forums.phpfreaks.com/topic/263495-verify-string/#findComment-1350365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.