Yii Framework Forum: datetime validation (format) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

datetime validation (format) Rate Topic: -----

#1 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,009
  • Joined: 30-October 09
  • Location:UK

Posted 19 July 2010 - 05:17 PM

I'm using a datetime picker and have set this to insert the datetime into a form field in the format: 19 Jul 2010 14:00

Now I want to use the CTypeValidator to validate this to type 'datetime', but I'm having difficulty specifying 'datetimeFormat'. From the patterns mentioned on http://www.yiiframew...CDateTimeParser it seems I may not be able to validate to that particular format.

So what other options do I have to perform this validation?
0

#2 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,009
  • Joined: 30-October 09
  • Location:UK

Posted 20 July 2010 - 04:05 AM

Anybody have any suggestions for this?
0

#3 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,009
  • Joined: 30-October 09
  • Location:UK

Posted 25 July 2010 - 03:22 PM

I did this in the end:

public function dateTimeCheck()
{
	if(!preg_match("/(\d{2})\s([a-z]{3})\s(\d{4})\s(\d{2}):(\d{2})/i", $this->start_datetime))
	{
		$this->addError('start_datetime', 'Start Date/Time must be in valid format');
	}
}

If anyone has any better solutions please let me know!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users