phpSensei Posted August 5, 2007 Share Posted August 5, 2007 I really Suck with delimeters and Regular expressions so can someone help me? I have a date of birth field which needs to be in this format dd/mm/yyyy... But I want the script to detect if the format is as followed " Number Number / Number Number / Number Number Number Number/ So it contains no Strings, and I want to use some kind of explode to see if it has three sections and each seperated by "/"... Anyone help? Link to comment https://forums.phpfreaks.com/topic/63425-preg_match/ Share on other sites More sharing options...
wildteen88 Posted August 5, 2007 Share Posted August 5, 2007 A very basic regex pattern: $dob = '02/01/1964'; echo '<b>DOB: </b>' . $dob . '<br />'; if(preg_match('|[0-9]{2}/[0-9]{2}/[0-9]{4}|', $dob)) { echo 'Date of birth is in the correct format'; } else { echo 'Date of birth is not in the correct format'; } Link to comment https://forums.phpfreaks.com/topic/63425-preg_match/#findComment-316314 Share on other sites More sharing options...
tibberous Posted August 6, 2007 Share Posted August 6, 2007 If you don't like regular expressions, explodes are normally a great alternative. $dob = explode("/", $dob); if(count($dob) != 3){ // wrong format }else { // right format } This doesn't check to make sure the parts are a set length. It would probably be better to cast the parts as int's and check the value that it would be to just make sure they contained two numbers - both because the two numbers could be out of range, and because it seems weird to require leading zeros. Link to comment https://forums.phpfreaks.com/topic/63425-preg_match/#findComment-316572 Share on other sites More sharing options...
phpSensei Posted August 6, 2007 Author Share Posted August 6, 2007 Wow, they both work.. Thanks guys, I really think this forum is the greatest of all of them. Link to comment https://forums.phpfreaks.com/topic/63425-preg_match/#findComment-316725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.