Jump to content

Date regex


Kemik

Recommended Posts

Hello all,

 

I'm trying to create a regex which only allows dates in the following format:

 

dd-mm-yyyy

 

So I can insert it in to my database (DATETIME).

 

		if(!eregi("(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d", $str)) {
		$this->validation->set_message('datetime', 'The %s field must be in this format: dd-mm-yyyy');
		return FALSE;
	} else {
		return TRUE;
	}

 

If I try it, I get the error The datetime field must be in this format: dd-mm-yyyy.

 

Can anyone see where I'm going wrong? Thanks.

Link to comment
https://forums.phpfreaks.com/topic/69464-date-regex/
Share on other sites

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.