JeremyCanada26 Posted October 27, 2010 Share Posted October 27, 2010 I have an integer that I'd like to validate to ensure that it is a valid number between 1 and 99999999999999999999(20 digits). I'm thinking about using the following, but I'm not sure what the max range is on the FILTER_VALIDATE_INT options. return filter_var($_REQUEST['r'], FILTER_VALIDATE_INT, array("options" => array("min_range"=>1, "max_range"=>99999999999999999999))); Quote Link to comment https://forums.phpfreaks.com/topic/217053-looking-to-validate-an-integer-up-to-20-digits-length/ Share on other sites More sharing options...
Anti-Moronic Posted October 27, 2010 Share Posted October 27, 2010 I've never used this filter or heard of it so can't help there. But, you can easily validate this with a simple regex. if(preg_match("/^[[:digit:]]{1,20}$/", $_REQUEST['r'])){ echo 'match'; } Quote Link to comment https://forums.phpfreaks.com/topic/217053-looking-to-validate-an-integer-up-to-20-digits-length/#findComment-1127322 Share on other sites More sharing options...
JeremyCanada26 Posted October 28, 2010 Author Share Posted October 28, 2010 Anti-Moronic, thanks man. The regex has change slightly since you gave it to me though, if(preg_match("/^[1-9][0-9]{0,19}$/", $_POST['value'])) { return true; } Quote Link to comment https://forums.phpfreaks.com/topic/217053-looking-to-validate-an-integer-up-to-20-digits-length/#findComment-1127330 Share on other sites More sharing options...
Anti-Moronic Posted October 28, 2010 Share Posted October 28, 2010 Great to see it helped! Makes my day a little bit brighter Quote Link to comment https://forums.phpfreaks.com/topic/217053-looking-to-validate-an-integer-up-to-20-digits-length/#findComment-1127342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.