M.O.S. Studios Posted November 28, 2008 Share Posted November 28, 2008 Hey guys, I need a function that can tell if any of the characters within var are a non integer. basically its to verify that the value entered is a valid phone number Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/ Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 Regex for US phone numbers: http://regexlib.com/REDetails.aspx?regexp_id=607 Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-701087 Share on other sites More sharing options...
M.O.S. Studios Posted November 28, 2008 Author Share Posted November 28, 2008 no no, i need a function that can tell if any of the character are not intagers. so 2g4 would come back as false but 224 would come back as true Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-701105 Share on other sites More sharing options...
revraz Posted November 28, 2008 Share Posted November 28, 2008 http://us3.php.net/is_int Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-701111 Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 is_int() will only return if the data type of the variable is INT....use is_numeric() Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-701114 Share on other sites More sharing options...
Mark Baker Posted November 28, 2008 Share Posted November 28, 2008 Of course, is_numeric() will return true for '1.5e-2', '0xAB' and other similar variants, non of which remotely resembles a telephone number. What was wrong with the original response pointing you to http://regexlib.com/REDetails.aspx?regexp_id=607 Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-701119 Share on other sites More sharing options...
M.O.S. Studios Posted November 28, 2008 Author Share Posted November 28, 2008 thanks guys this is what i did if(!is_numeric($_POST['phone1'])){$error=1;$phone=1;} if(!is_numeric($_POST['phone2'])){$error=1;$phone=1;} if(!is_numeric($_POST['phone3'])){$error=1;$phone=1;} Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-701140 Share on other sites More sharing options...
revraz Posted November 28, 2008 Share Posted November 28, 2008 No problem, but regex is still better. Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-701144 Share on other sites More sharing options...
Mark Baker Posted November 28, 2008 Share Posted November 28, 2008 so 3.14159 qualifies as a valid phone number And in an amazing coincidence, it's the phone number of the local pizza house. Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-701154 Share on other sites More sharing options...
M.O.S. Studios Posted February 5, 2009 Author Share Posted February 5, 2009 ok i figured it all out this is the new code that only allowes phone numbers, im 100% this works like it is suppost to preg_match('/(^[0-9]*)/i', $_POST['ship_phone1'].$_POST['ship_phone2'].$_POST['ship_phone3'], $matches); if($_POST['ship_phone1'].$_POST['ship_phone2'].$_POST['ship_phone3'] == $matches[0]) { if($_POST['ship_phone1']<="199") {$error .="Your Area Code cannot start with 1 and must be 3 digits long.<br>"."\n";} if($_POST['ship_phone2']<="199") {$error .="Your Phone Number cannot start with 1 and must be 3 digits long.<br>"."\n";} if(strlen($_POST['ship_phone3'])!="4") { $error .="Your Phone Number Must contain 10 digits.<br>"."\n"; } } else { $error .="Your Phone Number Can only contain characters 0-9.<br>"."\n"; } Link to comment https://forums.phpfreaks.com/topic/134653-intagers-only/#findComment-755429 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.