/* without JS code it's just HTML5 validation */
DigitsInputHelper("#donate", 2, '.');
DigitsInputHelper("#age", 0);
$("#dateF").datepicker({
dateFormat: "dd.mm.yy",
onSelect: function (dateText) {
if ($(this).attr("required") !== undefined) {
$(this).valid();
}
}
});
/* jQuery validation */
$.extend(jQuery.validator.messages, {
required: "Поле не может быть пустым!",
email: "По такому адресу никакая почта не дойдёт!",
date: "Дата это: дд.мм.гггг",
number: "Только целые числа!",
max: jQuery.validator.format("Уж поздно Вам! Мы младше {0}."),
min: jQuery.validator.format("Мал ты слишко. Подрасти до {0}.")
});
/* custom methods */
$.validator.addMethod("numberWithTwoDecimalPlaces", function (value, element) {
return this.optional(element) || /^\d+(\.\d{0,2})?$/i.test(value);
}, "Денежки только такие: {Рубли много}[.копейки только две]");
$.validator.addMethod("notZero", function (value, element) {
return this.optional(element) || !/(^0+$)|(^0*\.0*$)/i.test(value);
}, "Ноль за все труды! Так нельзя!");
$.validator.methods.date = function(value, element) {
console.log("validDate = " + value);
console.log("parse = " + parseDate(value));
console.log("!== = " + (parseDate(value) !== 'Invalid Date'));
return this.optional(element) ||
isValidDate(value) === true;
};
// looks like only id is possible here
$("#vform").validate({
rules: {
donate: "numberWithTwoDecimalPlaces notZero",
/* The bad thing is that rule is binded here. So when you are looking at HTML code you can't be sure whether it is set or not :) */
dateF: {
date: true, // methods.date - has been changed
dateNowOrPast: true
}
}
});
//*/
/* Allows only digits and one point input, restrics length of mantissa */
function DigitsInputHelper(inputSelector, mantissaLength, decimalSeparator) {
if ($(inputSelector).length > 0) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.