In my CakePHP-1.2 application, I am using the date format 01-Jan-2012
Which date validation rule should I use to test it?
I tried array(‘date’, ‘dMy’) . But it is not working.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
By reading the book, you can see that you cannot use separators in the date validation field for the algorithm you have selected. You will need to create a custom validation rule. You can do this using a Custom Regular Expression rule:
'/^((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\ Feb(ruary)?\\ (((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\-(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\-((1[6-9]|[2-9]\\d)\\d{2})$/';Note: This rule is a modified version of the canned ones that cake is shipped with.
So, you would want to do:
Note: the ‘i’ at the end of the regular expression, this simply denotes that it is a
Case Insensitivematch. This will match 24-Dec-2006, 24-DEC-2006, and 24-dec-2006 alike. Remove it if you want to accept the case sensitive match.Now, you can simply run that rule against the field in question, and you should be good to go.
Good luck.