webguync Posted November 15, 2010 Share Posted November 15, 2010 Hi, I need to add a function for a date field on a form being submitted to MySQL DB. Something similar to this for a website field, except it shoudl make sure the format is in 01/05/2010 or 2numbers/2 numbers/4 numbers format... if(!mb_eregi("^[a-zA-Z0-9-#_.+!*'(),/&:;=?@]*$", $website)) $this->setError('website', 'invalid website'); elseif(mb_strlen(trim($website)) > 120) $this->setError('website', 'too long! 120 characters'); thanks in advance for any assistance. Quote Link to comment https://forums.phpfreaks.com/topic/218770-function-to-determine-if-date-field-is-correct-on-form/ Share on other sites More sharing options...
Pikachu2000 Posted November 15, 2010 Share Posted November 15, 2010 If it's going into a database, shouldn't the format be YYYY-MM-DD? Quote Link to comment https://forums.phpfreaks.com/topic/218770-function-to-determine-if-date-field-is-correct-on-form/#findComment-1134638 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 Seconded, the MySQL data format is very close to ISO 8601: "YYYY-MM-DD HH:ii:ss.uuuu" Also, ereg is deprecated, use preg_* -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218770-function-to-determine-if-date-field-is-correct-on-form/#findComment-1134642 Share on other sites More sharing options...
webguync Posted November 15, 2010 Author Share Posted November 15, 2010 well, yea, but this is just for the client side. I think most users are used to putting in dates as mm/dd/yyyy format. At least in the US. In the DB it can display YYYY-MM-DD. Quote Link to comment https://forums.phpfreaks.com/topic/218770-function-to-determine-if-date-field-is-correct-on-form/#findComment-1134650 Share on other sites More sharing options...
Pikachu2000 Posted November 15, 2010 Share Posted November 15, 2010 Depending on how you have the form set up, you may be able to simply use checkdate() Quote Link to comment https://forums.phpfreaks.com/topic/218770-function-to-determine-if-date-field-is-correct-on-form/#findComment-1134653 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 This is why we have JavaScript date pickers. Have the user click the date on a calendar, and the JS fills in YYYY-MM-DD for you. Validating user input has to be by hand, usually with explode(). How can you tell if 3/14/11 is valid? If they live in England, it's not valid. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218770-function-to-determine-if-date-field-is-correct-on-form/#findComment-1134656 Share on other sites More sharing options...
webguync Posted November 15, 2010 Author Share Posted November 15, 2010 Thanks I will look into a JS datepicker Quote Link to comment https://forums.phpfreaks.com/topic/218770-function-to-determine-if-date-field-is-correct-on-form/#findComment-1134659 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.