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. 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? 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 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. 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() 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 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 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
Archived
This topic is now archived and is closed to further replies.