jQuery.fn.validDigits = function() {
	var isValid = true;
	
	this.each(function() {
		var value = $(this).val();
		
		var regex=new RegExp("^[\\-\\+]?\\d+\\.?\\d*$");
		if (value && value.length > 0) {
			if(!regex.exec(value)) {
				$(this).val("");
				alert("Error: acest camp poate contine numai cifre");
				isValid = false;
			}
		}
	});
	
	return isValid;
}

jQuery.fn.validPhone = function() {
	var isValid = true;
	
	this.each(function() {
		var value = $(this).val();
	
		var regex=new RegExp("^[\\d\\-\\+]{3,}$");
		if (value && value.length > 0) {
			if(!regex.exec(value)) {
				$(this).val("");
				alert("Error: numar de telefon introdus incorect");
				isValid = false;
			}
		}
	});
	
	return isValid;
}

jQuery.fn.validEmail = function() {
	var isValid = true;
	
	this.each(function() {
		var value = $(this).val();
	
		var regex=new RegExp(".*");
		
		if (value && value.length > 0) {
			if(!regex.exec(value)) {
				$(this).val("");
				alert("Error: adresa de email introdusa incorect");
				isValid = false;
			}
		}
	});	
	
	return isValid;
}

jQuery.fn.isNotEmpty = function() {
	var isValid = true;
	
	this.each(function() {
		var value = $(this).val();
	
		var regex = new RegExp("^[^\\s].+$");
		if(!regex.exec(value)) {
			$(this).val("");
			alert("Error: acest camp este obligatoriu si nu poate fi vid");
			isValid = false;
		} 	
	});	
	
	return isValid;
}

jQuery.fn.isValidInput = function(settings) {
	settings = jQuery.extend({
		type: 'text',
		notEmpty: false
	}, settings);
	
	isValid = false;
	
	this.each(function() {
		if (settings.notEmpty == true) {
			isValid = $(this).isNotEmpty();
			if (!isValid) {
				return false;
			}
		}
		
		if (settings.type == 'digits') {
			isValid = $(this).validDigits();
		} else if (settings.type == "phone") {
			isValid = $(this).validPhone();
		} else if (settings.type == "email") {
			isValid = $(this).validEmail();
		} else {
			isValid = true;
		}
		
		return isValid;
	});
	
	return isValid;
}
