Jump to content

Function to determine if date field is correct on form


webguync

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.