function OnlyDigits(selector){
	$(selector).keypress(function (e){
		if(this.value.match(/[\d]/)){
			$(this).next().html('').fadeOut('normal');
		}
		
		if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)){
			$(this).next().html('introdu doar cifre').fadeIn('normal');
			return false;
		}
		
		
	});
	
	return false;
}

$.validator.addMethod(
        "regex",
        function(value, element, regexp) {
            var check = false;
            var re = new RegExp(regexp);
            return this.optional(element) || re.test(value);
        },
        "Introdu o valoare valida"
);

$.validator.addMethod(
	"phone", function(phone_number, element) {
		var digits = "0123456789";
		var phoneNumberDelimiters = "()- ext.";
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
		var minDigitsInIPhoneNumber = 10;
		s = stripCharsInBag(phone_number,validWorldPhoneChars);
		return this.optional(element) || isInteger(s) && s.length >= minDigitsInIPhoneNumber;
	}, "Introdu un numar de telefon valid"
);

function isInteger(s){
	var i;
	
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))){
			return false;
		}
	}

	return true;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";

	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	
	return returnString;
}
