$.validator.addMethod(
	"regex",
	function(value, element, regexp){
		var re = new RegExp(regexp);
		return this.optional(element) || value.match(re);
	},
	"Invalid format"
);

function isDigit(p) {
	var re = new RegExp("^[0-9]+$");
	return p.match(re); 
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
   } 
   return this;
}

function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function isDate(day, month, year){
	if (! isDigit(day)) return false;
	if (! isDigit(month)) return false;
	if (! isDigit(year)) return false;

	var daysInMonth = DaysArray(12);

	if (month<1 || month>12){
		return false;
	}
	else if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false;
	}
	else return true;
}

$.validator.addMethod(
	"birthdate",
	function(value, element, param){
		return isDate(jQuery(param[0]).val(), jQuery(param[1]).val(), jQuery(param[2]).val());
	},
	"Invalid date"
);

$.validator.addMethod(
	"isempty",
	function(value, element, param){
		return (jQuery(param[0]).val().length > 0 && jQuery(param[1]).val().length > 0) ? false : true;
	},
	"Error"
);