verN Posted March 3, 2007 Share Posted March 3, 2007 hiyya all, I wanted to know how to validate the phone number entered by the user. In my database phone number is defined as int(3) unsigned. Would it be best to use php and use regular expersssions or use javascript. Any code would be beneficial $phone = trim($_POST['phone']); thanks in advance Link to comment https://forums.phpfreaks.com/topic/41002-solved-phone-number-validation/ Share on other sites More sharing options...
pocobueno1388 Posted March 3, 2007 Share Posted March 3, 2007 Why do you set it as int(3)? That means it can only hold 3 integers and a phone number is longer than that. Are you wanting to validate phone numbers internationally, US numbers, or what? Link to comment https://forums.phpfreaks.com/topic/41002-solved-phone-number-validation/#findComment-198546 Share on other sites More sharing options...
verN Posted March 4, 2007 Author Share Posted March 4, 2007 yeah i changed the phoneNo variable to varchar(10) how do i validate this to ensure onlu numbers are entered Link to comment https://forums.phpfreaks.com/topic/41002-solved-phone-number-validation/#findComment-199026 Share on other sites More sharing options...
The14thGOD Posted March 4, 2007 Share Posted March 4, 2007 $phone_number = str_replace('-',"",$phone_number) That might work? Link to comment https://forums.phpfreaks.com/topic/41002-solved-phone-number-validation/#findComment-199028 Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 is_numeric() Orio. Link to comment https://forums.phpfreaks.com/topic/41002-solved-phone-number-validation/#findComment-199029 Share on other sites More sharing options...
verN Posted March 4, 2007 Author Share Posted March 4, 2007 how would i use the isNumeric value could you show the code for this would it be if(!empty){ isNumeric(phoneNo) return true; } else { return false; error[]=You need to enter numerc values; thanks Link to comment https://forums.phpfreaks.com/topic/41002-solved-phone-number-validation/#findComment-199032 Share on other sites More sharing options...
mmarif4u Posted March 4, 2007 Share Posted March 4, 2007 Use this function, Code: if(ereg("^[0-9]{3}-[0-9]{3}-[0-9]{4}$", $phone)) { echo "valid phonenumber"; } else { echo "invalid phonenumber"; } [0-9] This will check that the entered thing is number, {3} this will check the expression for 1st 3 numbers and so on for others. Link to comment https://forums.phpfreaks.com/topic/41002-solved-phone-number-validation/#findComment-199033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.