robcrozier Posted November 14, 2007 Share Posted November 14, 2007 HI all, i wonder if someone can help me with this. Im not very good with regular expressions but i would like to use the ereg() function to check for a date in this format: yyyy/mm/dd. any help appreciated! Cheers all! Quote Link to comment Share on other sites More sharing options...
dbo Posted November 14, 2007 Share Posted November 14, 2007 This is the wrong forum. But the regex is: /^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/ To verify ranges and what not you'll need more than this though. That just validates the format. yyyy/mm/dd Quote Link to comment Share on other sites More sharing options...
robcrozier Posted November 14, 2007 Author Share Posted November 14, 2007 sorry about the wrong forum but that doesn't seem to work? Quote Link to comment Share on other sites More sharing options...
dbo Posted November 14, 2007 Share Posted November 14, 2007 Define doesn't work. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 25, 2007 Share Posted November 25, 2007 I would say that dbo's regex is proper, but since you said you wanted it to work with ereg modified his code to wrap the items in () parens to use with preg_replace $output = preg_replace(/^([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2})$/,*,1977/1/1); to use with ereg, if (ereg ("([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2})", $date, $regs)) { echo "$regs[3].$regs[2].$regs[1]"; } else { echo "Invalid date format: $date"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.