$(document).ready(function() {
$.validator.addMethod("dynamicdate", function(value, element, params) {
var regex=null,match_exec=null;
var formatstr=(typeof params[1]==='undefined' || params[1]==null || params[1]=='')?'ddmmyyyy':params[1];
var seperator=(typeof params[0]==='undefined' || params[0]==null || params[0]=='')?'/':params[0];
//exection set: ymd : after date exection, store index in format ymd*/
var format_arr={
ddmmyyyy:{dateset:[2,1,0],execset:[5,3,1],regset:[1,2,1,2,4,4],arr:['DD','MM','YYYY']},
mmddyyyy:{dateset:[2,0,1],execset:[5,1,3],regset:[1,2,1,2,4,4],arr:['MM','DD','YYYY']},
yyyymmdd:{dateset:[0,1,2],execset:[1,3,5],regset:[4,4,1,2,1,2],arr:['YYYY','MM','DD']}
};
/* DD/MM/YYYY: \d{1,2}\/\d{1,2}\/\d{2,4} */
regex=new RegExp('^(\\d{'+format_arr[formatstr].regset[0]+','+format_arr[formatstr].regset[1]+'})(\\'+seperator+')(\\d{'+format_arr[formatstr].regset[2]+','+format_arr[formatstr].regset[3]+'})(\\'+seperator+')(\\d{'+format_arr[formatstr].regset[4]+','+format_arr[formatstr].regset[5]+'})$');
var date_formatwithseperator=format_arr[formatstr].arr[0]+seperator+format_arr[formatstr].arr[1]+seperator+format_arr[formatstr].arr[2];
match_exec=regex.exec(value);
if(match_exec!=null) {
var y=format_arr[formatstr].execset[0],m=format_arr[formatstr].execset[1],d=format_arr[formatstr].execset[2];
var yyyy = parseInt(match_exec[y],10),
mm=parseInt(match_exec[m],10),
dd=parseInt(match_exec[d],10),
newdate = new Date(yyyy,mm-1,dd,0,0,0,0);
return (mm === (newdate.getMonth()+1) && dd === newdate.getDate() && yyyy === newdate.getFullYear());
}
return;
}, jQuery.validator.format("Please enter a valid date with format {2}"));
$.validator.addMethod("dropdowntime",function(value,element,params) {
var hr=$("#"+params[0]).val(),minute=parseInt(value,10);
return (hr>0 || minute>0 );
},"Please select your time");
//Enter valid time.Eg.,11:55,11:55 AM,11:55AM,11:55am,11:55 pm,11:55:25 pm
$.validator.addMethod("dynamictime", function (value, element) {
return this.optional(element) || /^(\d{1,2})[:](\d{2})(:\d{2})?(\s+)?([ap]m)?$/i.test(value);
}, "Please enter a valid time.");
})
</script>
Message
Maximum allowed Elements would be 25
We use cookies to ensure you get the best experience on our website and also used by third party softwares