phpretard Posted April 24, 2009 Share Posted April 24, 2009 (555)"space"123-4567 I am trying to validate this. Can't figure what's wrong??? if(!ereg("^([0-9]{3}) [0-9]{3}-[0-9]{4}$", $homephone)){ echo "No good"; } Can anyone help a brotha out? Thank you! Link to comment https://forums.phpfreaks.com/topic/155490-phone-number-validation/ Share on other sites More sharing options...
rhodesa Posted April 24, 2009 Share Posted April 24, 2009 ereg will be depreciated in PHP6 if(!preg_match('/^\(\d{3}\) \d{3}-\d{4}$/', $homephone)){ echo "No good"; } Link to comment https://forums.phpfreaks.com/topic/155490-phone-number-validation/#findComment-818198 Share on other sites More sharing options...
radi8 Posted April 24, 2009 Share Posted April 24, 2009 I got this from the ereg documentation, try this one: <?php if (ereg("^((\([0-9]{3}\) ?)|([0-9]{3}-))?[0-9]{3}-[0-9]{4}$",$homephone)) ?> to make it clear: ^ means begin here (startpoint of ereg) $ means end here (endpoint of ereg) * stand for endless characters (I want A-Z, a-z, 0-9 and the other characters to apear from 0 to endless optional you can write {1,5} for min 1 times a character or max 5 times a characters instead of * {1,2} means min 1 time a character and max 2 times a character (optional you can write * intead of {1,2} {1} stand for max 1 time a character \ means from here special characters (like .-_$ and so on) | means OR Link to comment https://forums.phpfreaks.com/topic/155490-phone-number-validation/#findComment-818199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.