Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure closing of prompt; new validation rule for dates in d/m/y format. #858

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions js/contrib/other-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"regex": /^([A-PR-UWYZa-pr-uwyz]([0-9]{1,2}|([A-HK-Ya-hk-y][0-9]|[A-HK-Ya-hk-y][0-9]([0-9]|[ABEHMNPRV-Yabehmnprv-y]))|[0-9][A-HJKS-UWa-hjks-uw])\ {0,1}[0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}|([Gg][Ii][Rr]\ 0[Aa][Aa])|([Ss][Aa][Nn]\ {0,1}[Tt][Aa]1)|([Bb][Ff][Pp][Oo]\ {0,1}([Cc]\/[Oo]\ )?[0-9]{1,4})|(([Aa][Ss][Cc][Nn]|[Bb][Bb][Nn][Dd]|[BFSbfs][Ii][Qq][Qq]|[Pp][Cc][Rr][Nn]|[Ss][Tt][Hh][Ll]|[Tt][Dd][Cc][Uu]|[Tt][Kk][Cc][Aa])\ {0,1}1[Zz][Zz]))$/,
"alertText": "* Invalid postcode"
};
$.validationEngineLanguage.allRules["postcodeAU"] = {
// Australian postcodes | Accepts 1234 format zipcodes
// "regex": /^\d{4}?$/,
// From: http://www.etl-tools.com/regular-expressions/is-australian-post-code.html
"regex": /^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$/,
"alertText": "* Invalid postcode"
};
$.validationEngineLanguage.allRules["postcodeNL"] = {
// NL zip codes | Accepts 1234AA format zipcodes
"regex": /^\d{4}[a-zA-Z]{2}?$/,
Expand Down
17 changes: 14 additions & 3 deletions js/jquery.validationEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
// delegate fields
form.on(options.validationEventTrigger, "["+options.validateAttribute+"*=validate]:not([type=checkbox]):not([type=radio]):not(.datepicker)", methods._onFieldEvent);
form.on("click", "["+options.validateAttribute+"*=validate][type=checkbox],["+options.validateAttribute+"*=validate][type=radio]", methods._onFieldEvent);
form.on(options.validationEventTrigger,"["+options.validateAttribute+"*=validate][class*=datepicker]", {"delay": 300}, methods._onFieldEvent);
form.on(options.validationEventTrigger, "["+options.validateAttribute+"*=validate][class*=datepicker]", {"delay": 300}, methods._onFieldEvent);
}
if (options.autoPositionUpdate) {
$(window).bind("resize", {
Expand All @@ -81,7 +81,7 @@
// unbind fields
form.off(options.validationEventTrigger, "["+options.validateAttribute+"*=validate]:not([type=checkbox]):not([type=radio]):not(.datepicker)", methods._onFieldEvent);
form.off("click", "["+options.validateAttribute+"*=validate][type=checkbox],["+options.validateAttribute+"*=validate][type=radio]", methods._onFieldEvent);
form.off(options.validationEventTrigger,"["+options.validateAttribute+"*=validate][class*=datepicker]", methods._onFieldEvent);
form.off(options.validationEventTrigger, "["+options.validateAttribute+"*=validate][class*=datepicker]", methods._onFieldEvent);

// unbind form.submit
form.off("submit", methods._onSubmitEvent);
Expand Down Expand Up @@ -214,6 +214,8 @@

if($(this).is("form") || $(this).hasClass("validationEngineContainer")) {
closingtag = "parentForm"+methods._getClassName($(this).attr("id"));
} else if ($(this).is("select") && options.prettySelect && $(this).is(":hidden")) {
closingtag = methods._getClassName(options.usePrefix + $(this).attr('id') + options.useSuffix) +"formError";
} else {
closingtag = methods._getClassName($(this).attr("id")) +"formError";
}
Expand Down Expand Up @@ -548,7 +550,11 @@
if(field.hasClass(options.ignoreFieldsWithClass))
return false;

if (!options.validateNonVisibleFields && (field.is(":hidden") && !options.prettySelect || field.parent().is(":hidden")))
if (!options.validateNonVisibleFields && (field.is(":hidden") && !options.prettySelect || field.parent().is(":hidden")))
return false;


if (field.hasClass('datepicker') && field.data('datepicker') && field.data('datepicker').picker.is(':visible') )
return false;

var rulesParsing = field.attr(options.validateAttribute);
Expand Down Expand Up @@ -1765,6 +1771,11 @@
* field
*/
_closePrompt: function(field) {
if(field.data('jqv-prompt-at') instanceof jQuery ){
field = field.data('jqv-prompt-at');
} else if(field.data('jqv-prompt-at')) {
field = $(field.data('jqv-prompt-at'));
}
var prompt = methods._getPrompt(field);
if (prompt)
prompt.fadeTo("fast", 0, function() {
Expand Down
57 changes: 41 additions & 16 deletions js/languages/jquery.validationEngine-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"alertText": "* Maximum ",
"alertText2": " characters allowed"
},
"groupRequired": {
"groupRequired": {
"regex": "none",
"alertText": "* You must fill one of the following fields",
"alertTextCheckboxMultiple": "* Please select an option",
Expand Down Expand Up @@ -95,6 +95,12 @@
"regex":/^\d{5}$|^\d{5}-\d{4}$/,
"alertText":"* Invalid zip format"
},
"postcodeAU": {
// "regex": /^\d{4}?$/,
// From: http://www.etl-tools.com/regular-expressions/is-australian-post-code.html
"regex": /^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$/,
"alertText": "* Invalid postcode"
},
"integer": {
"regex": /^[\-\+]?\d+$/,
"alertText": "* Not a valid integer"
Expand All @@ -105,21 +111,40 @@
"alertText": "* Invalid floating decimal number"
},
"date": {
// Check if date is valid by leap year
"func": function (field) {
var pattern = new RegExp(/^(\d{4})[\/\-\.](0?[1-9]|1[012])[\/\-\.](0?[1-9]|[12][0-9]|3[01])$/);
var match = pattern.exec(field.val());
if (match == null)
return false;

var year = match[1];
var month = match[2]*1;
var day = match[3]*1;
var date = new Date(year, month - 1, day); // because months starts from 0.

return (date.getFullYear() == year && date.getMonth() == (month - 1) && date.getDate() == day);
},
"alertText": "* Invalid date, must be in YYYY-MM-DD format"
// Check if date is valid by leap year
"func": function (field) {
var pattern = new RegExp(/^(\d{4})[\/\-\.](0?[1-9]|1[012])[\/\-\.](0?[1-9]|[12][0-9]|3[01])$/);
var match = pattern.exec(field.val());
if (match == null)
return false;

var year = match[1];
var month = match[2]*1;
var day = match[3]*1;
//var date = new Date(year, month - 1, day); // because months starts from 0.
var date = new Date(Date.UTC(year, month - 1, day)); // because months starts from 0.

return (date.getFullYear() == year && date.getMonth() == (month - 1) && date.getDate() == day);
},
"alertText": "* Invalid date, must be in YYYY-MM-DD format"
},
"date_dmy": {
// Check if date is valid by leap year
"func": function (field) {
var pattern = new RegExp(/^(0?[1-9]|[12][0-9]|3[01])[\/\-\.](0?[1-9]|1[012])[\/\-\.](\d{4})$/);
var match = pattern.exec(field.val());
if (match == null)
return false;

var day = match[1]*1;
var month = match[2]*1;
var year = match[3];
//var date = new Date(year, month - 1, day); // because months starts from 0.
var date = new Date(Date.UTC(year, month - 1, day)); // because months starts from 0.

return (date.getFullYear() == year && date.getMonth() == (month - 1) && date.getDate() == day);
},
"alertText": "* Invalid date, must be in DD-MM-YYYY format"
},
"ipv4": {
"regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/,
Expand Down