grippat Posted October 2, 2007 Share Posted October 2, 2007 I'm pretty inexperienced with regular expressions and I'm trying to come up with a regular expression that validates a birthday in the following format: 1969-12-01So far I haven't had any luck. Anyone know how to do it? Thanks! Link to comment Share on other sites More sharing options...
JamesB Posted October 2, 2007 Share Posted October 2, 2007 hey,Im kinda new to PHP, but I think this solution should work: $validation = explode("-", 1969-12-01)if (strlen($validation[0]) != 4 ) { print("Invalid Year Format");}elseif (($validation[1] < 0) || ($validation[1] > 12)) { print ("Invalid Month Format");}elseif (($validation[2] < 0) || ($validation > 31)) { print("Invalid Day Format");} Link to comment Share on other sites More sharing options...
grippat Posted October 2, 2007 Author Share Posted October 2, 2007 Thanks JamesB, but I think I got it with the regex solution, the following seems to do the trick:/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/ Link to comment Share on other sites More sharing options...
justsomeguy Posted October 2, 2007 Share Posted October 2, 2007 Keep in mind that only validates the format, they can still enter an invalid date like 2000-99-99 Link to comment Share on other sites More sharing options...
grippat Posted October 2, 2007 Author Share Posted October 2, 2007 Keep in mind that only validates the format, they can still enter an invalid date like 2000-99-99Yeah. I was only looking to validate the format. I already have another piece of code checking for a valid date. Thanks though. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.