cakephp - Date validation not working for the date format 'd-M-Y' -
in cakephp-1.2 application, using date format 01-jan-2012
which date validation rule should use test it?
i tried array('date', 'dmy') . not working.
by reading book, can see cannot use separators in date validation field algorithm have selected. need create custom validation rule. can using 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: rule modified version of canned ones cake shipped with.
so, want do:
var $validate = array( 'born' => array( '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})$/i', 'message' => 'enter valid date in day-mon-year format.' ) );
note: 'i' @ end of regular expression, denotes case insensitive
match. match 24-dec-2006, 24-dec-2006, , 24-dec-2006 alike. remove if want accept case sensitive match.
now, can run rule against field in question, , should go.
good luck.
Comments
Post a Comment