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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.