nvee Posted November 14, 2009 Share Posted November 14, 2009 I have a simple function which checks if a variables passed into the function is numeric and if it is the lenght it should be. Somehow it keeps on returning the error, even if the number is correct. code in html ... INTVALIDATE($tel,10); function code ... function INTVALIDATE($var,$lenght) { $value = strlen($var); if($var != $value AND !is_numeric($var)) { $intresult = "<li>Some of your numbers does not match the correct lenght or is not numeric, please correct this!</li>"; } return $intresult; } Link to comment https://forums.phpfreaks.com/topic/181497-number-validation-not-returning-the-correct-results/ Share on other sites More sharing options...
rarebit Posted November 14, 2009 Share Posted November 14, 2009 Your function isn't making too much sense to me (hung over), what are the specifications of your function? You pass a 'length', but then not use it anywhere! The 'if' would probably be an 'OR', not 'AND'. If it's for telephone numbers then i'd expect to receive spaces, ext's, prefixes, codes, etc... Therefore i'd suggest looking at PCRE (e.g. regex), see the manual ([url=http://uk2.php.net/manual/en/function.preg-match.php]preg-match . Also I did a quick google search for 'pcre telephone' and the first result was: http://benramsey.com/tag/pcre/ Link to comment https://forums.phpfreaks.com/topic/181497-number-validation-not-returning-the-correct-results/#findComment-957400 Share on other sites More sharing options...
Andy-H Posted November 14, 2009 Share Posted November 14, 2009 define("MIN_RANGE", 0); //Minimum integer amount desired... define("MAX_RANGE", 100); // Maximum integer amount desired... $options = array( 'options' => array( 'min_range' => MIN_RANGE, 'max_range' => MAX_RANGE ) ); $var = 50; if ( filter_var( $var, FILTER_VALIDATE_INT, $options ) === true ) { # Var validated as int between 0 and 100 } else { # Var didn't validate... } filter_var Link to comment https://forums.phpfreaks.com/topic/181497-number-validation-not-returning-the-correct-results/#findComment-957409 Share on other sites More sharing options...
rarebit Posted November 14, 2009 Share Posted November 14, 2009 oooh, I love my post, pity I can't alter it! LOL P.S. Just reading these new rules now... Link to comment https://forums.phpfreaks.com/topic/181497-number-validation-not-returning-the-correct-results/#findComment-957418 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.