Skip to content

Commit cda88af

Browse files
author
t_bertrand
committed
Version 1.5.1
- Fixed OPTIONAL rule when validating multiline input or textarea - Not validating [READONLY] inputs anymore
1 parent 61f4c62 commit cda88af

File tree

3 files changed

+44
-46
lines changed

3 files changed

+44
-46
lines changed

html5-form-validation.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"validation",
1010
"input"
1111
],
12-
"version": "1.5.0",
12+
"version": "1.5.1",
1313
"author": {
1414
"name": "Tom Bertrand",
1515
"url": "http://www.runningcoder.org/jqueryvalidation/"

jquery.validation.js

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
* Licensed under the MIT license
55
*
66
* @author Tom Bertrand
7-
* @version 1.5.0 (2015-02-08)
7+
* @version 1.5.1 (2015-02-16)
88
* @link http://www.runningcoder.org/jqueryvalidation/
99
*
1010
* @note
1111
* Remove debug code: //\s?\{debug\}[\s\S]*?\{/debug\}
1212
*/
13-
;(function (window, document, $, undefined)
14-
{
13+
;(function (window, document, $, undefined) {
1514

1615
window.Validation = {
1716
form: [],
@@ -23,7 +22,9 @@
2322
* Fail-safe preventExtensions function for older browsers
2423
*/
2524
if (typeof Object.preventExtensions !== "function") {
26-
Object.preventExtensions = function (obj) { return obj; };
25+
Object.preventExtensions = function (obj) {
26+
return obj;
27+
};
2728
}
2829

2930
// Not using strict to avoid throwing a window error on bad config extend.
@@ -38,15 +39,15 @@
3839
var _rules = {
3940
NOTEMPTY: /./,
4041
INTEGER: /^\d+$/,
41-
NUMERIC: /^\d+(?:[\s,]\d{3})*(?:\.\d+)?$/,
42+
NUMERIC: /^\d+(?:[,\s]\d{3})*(?:\.\d+)?$/,
4243
MIXED: /^[\w\s-]+$/,
4344
NOSPACE: /^(?!\s)\S*$/,
4445
TRIM: /^[^\s].*[^\s]$/,
4546
DATE: /^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}(:\d{2})?)?$/,
4647
EMAIL: /^([^@]+?)@(([a-z0-9]-*)*[a-z0-9]+\.)+([a-z0-9]+)$/i,
4748
URL: /^(https?:\/\/)?((([a-z0-9]-*)*[a-z0-9]+\.?)*([a-z0-9]+))(\/[\w?=\.-]*)*$/,
4849
PHONE: /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/,
49-
OPTIONAL: /^.*$/,
50+
OPTIONAL: /./,
5051
COMPARISON: /^\s*([LV])\s*([<>]=?|==|!=)\s*([^<>=!]+?)\s*$/
5152
},
5253

@@ -185,7 +186,7 @@
185186
/**
186187
* Extends user-defined "options.message" into the default Validation "_message".
187188
*/
188-
function extendRules () {
189+
function extendRules() {
189190
options.rules = $.extend(
190191
true,
191192
{},
@@ -197,7 +198,7 @@
197198
/**
198199
* Extends user-defined "options.message" into the default Validation "_message".
199200
*/
200-
function extendMessages () {
201+
function extendMessages() {
201202
options.messages = $.extend(
202203
true,
203204
{},
@@ -212,7 +213,7 @@
212213
* - preventExtensions prevents from modifying the Validation "_options" object structure
213214
* - filter through the "_supported" to delete unsupported "options"
214215
*/
215-
function extendOptions () {
216+
function extendOptions() {
216217

217218
if (!(options instanceof Object)) {
218219
options = {};
@@ -330,7 +331,7 @@
330331
});
331332
// {/debug}
332333

333-
if ( !node.find('[' + _data.validation + '],[' + _data.regex + ']')[0]) {
334+
if (!node.find('[' + _data.validation + '],[' + _data.regex + ']')[0]) {
334335

335336
// {debug}
336337
options.debug && window.Debug.log({
@@ -390,7 +391,7 @@
390391
* Delegates the submit validation on data-validation and data-validation-regex attributes based on trigger.
391392
* Note: Disable the form submit function so the callbacks are not by-passed
392393
*/
393-
function delegateValidation () {
394+
function delegateValidation() {
394395

395396
_executeCallback(options.submit.callback.onInit, [node]);
396397

@@ -462,12 +463,12 @@
462463
*
463464
* @returns {boolean} true if no error(s) were found (valid form)
464465
*/
465-
function validateForm () {
466+
function validateForm() {
466467

467468
var isValid = true;
468469

469470
$.each(
470-
node.find('[' + _data.validation + ']:not([disabled]),[' + _data.regex + ']:not([disabled])'),
471+
node.find('[' + _data.validation + ']:not([disabled],[readonly]),[' + _data.regex + ']:not([disabled],[readonly])'),
471472
function (index, input) {
472473
if (!validateInput(input)) {
473474
isValid = false;
@@ -487,7 +488,7 @@
487488
*
488489
* @returns {boolean} true if no error(s) were found (valid input)
489490
*/
490-
function validateInput (input) {
491+
function validateInput(input) {
491492

492493
var inputName = $(input).attr('name');
493494

@@ -529,7 +530,7 @@
529530
if (validationArray instanceof Array && validationArray.length > 0) {
530531

531532
// "OPTIONAL" input will not be validated if it's empty
532-
if (value === '' && $.inArray('OPTIONAL', validationArray) !== -1) {
533+
if (value === '' && ~validationArray.indexOf('OPTIONAL')) {
533534
return true;
534535
}
535536

@@ -597,7 +598,7 @@
597598
*
598599
* @returns {*} Error if a mismatch occurred.
599600
*/
600-
function validateRule (value, rule, reversed) {
601+
function validateRule(value, rule, reversed) {
601602

602603
// Validate for "data-validation-regex" and "data-validation-regex-reverse"
603604
if (rule instanceof RegExp) {
@@ -716,7 +717,7 @@
716717
* @param {string} inputName Input where the error occurred
717718
* @param {string} error Description of the error to be displayed
718719
*/
719-
function registerError (inputName, error) {
720+
function registerError(inputName, error) {
720721

721722
if (!errors[inputName]) {
722723
errors[inputName] = [];
@@ -747,7 +748,7 @@
747748
*
748749
* @returns {boolean} false if an unwanted behavior occurs
749750
*/
750-
function displayOneError (inputName) {
751+
function displayOneError(inputName) {
751752

752753
var input,
753754
inputId,
@@ -859,15 +860,15 @@
859860
}
860861
}
861862

862-
input.unbind(event).on(event, function (a,b,c,d,e) {
863+
input.unbind(event).on(event, function (a, b, c, d, e) {
863864

864865
return function () {
865866
if (e) {
866867
if ($(c).hasClass(options.submit.settings.errorClass)) {
867-
resetOneError(a,b,c,d,e);
868+
resetOneError(a, b, c, d, e);
868869
}
869870
} else if ($(b).hasClass(options.submit.settings.errorClass)) {
870-
resetOneError(a,b,c,d);
871+
resetOneError(a, b, c, d);
871872
}
872873
};
873874

@@ -893,7 +894,7 @@
893894
/**
894895
* Display all of the errors
895896
*/
896-
function displayErrors () {
897+
function displayErrors() {
897898

898899
for (var inputName in errors) {
899900
if (!errors.hasOwnProperty(inputName)) continue;
@@ -959,7 +960,7 @@
959960
/**
960961
* Remove all of the input error(s) display.
961962
*/
962-
function resetErrors () {
963+
function resetErrors() {
963964

964965
errors = [];
965966
window.Validation.hasScrolled = false;
@@ -975,7 +976,7 @@
975976
* - This function will be overridden if "options.submit.settings.onSubmit" is defined
976977
* - The node can't be submitted by jQuery since it has been disabled, use the form native submit function instead
977978
*/
978-
function submitForm () {
979+
function submitForm() {
979980

980981
node[0].submit()
981982

@@ -986,7 +987,7 @@
986987
*
987988
* @returns {boolean}
988989
*/
989-
function destroy () {
990+
function destroy() {
990991

991992
resetErrors();
992993
node.find('[' + _data.validation + '],[' + _data.regex + ']').off(delegateSuffix + ' ' + resetSuffix);
@@ -1035,10 +1036,10 @@
10351036
* Execute function once the timer is reached.
10361037
* If the function is recalled before the timer ends, the first call will be canceled.
10371038
*/
1038-
var _typeWatch = (function(){
1039+
var _typeWatch = (function () {
10391040
var timer = 0;
1040-
return function(callback, ms){
1041-
clearTimeout (timer);
1041+
return function (callback, ms) {
1042+
clearTimeout(timer);
10421043
timer = setTimeout(callback, ms);
10431044
};
10441045
})();
@@ -1288,7 +1289,7 @@
12881289
rules = [rules];
12891290
}
12901291

1291-
for (var i=0; i<rules.length; i++) {
1292+
for (var i = 0; i < rules.length; i++) {
12921293
_api.alterValidationRules(rules[i]);
12931294
}
12941295

@@ -1480,7 +1481,7 @@
14801481
return false;
14811482
}
14821483

1483-
return node.each( function () {
1484+
return node.each(function () {
14841485

14851486
var $this = $(this),
14861487
validationData = $this.attr(_data.validation),
@@ -1521,7 +1522,7 @@
15211522
return false;
15221523
}
15231524

1524-
return node.each( function () {
1525+
return node.each(function () {
15251526

15261527
var $this = $(this),
15271528
validationData = $this.attr(_data.validation),
@@ -1618,15 +1619,15 @@
16181619
error[inputName] = [error[inputName]];
16191620
}
16201621

1621-
input = $(node.selector).find('[name="'+ inputName + '"]');
1622+
input = $(node.selector).find('[name="' + inputName + '"]');
16221623
if (!input[0]) {
16231624

16241625
// {debug}
16251626
window.Debug.log({
16261627
'node': node,
16271628
'function': '$.addError()',
16281629
'arguments': JSON.stringify(inputName),
1629-
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="'+ inputName + '"]")'
1630+
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="' + inputName + '"]")'
16301631
});
16311632

16321633
window.Debug.print();
@@ -1731,15 +1732,15 @@
17311732
var input;
17321733
for (var i = 0; i < inputName.length; i++) {
17331734

1734-
input = $(node.selector).find('[name="'+ inputName[i] + '"]');
1735+
input = $(node.selector).find('[name="' + inputName[i] + '"]');
17351736
if (!input[0]) {
17361737

17371738
// {debug}
17381739
window.Debug.log({
17391740
'node': node,
17401741
'function': '$.removeError()',
17411742
'arguments': JSON.stringify(inputName[i]),
1742-
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="'+ inputName[i] + '"]")'
1743+
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="' + inputName[i] + '"]")'
17431744
});
17441745

17451746
window.Debug.print();
@@ -1912,7 +1913,7 @@
19121913
console.table(this.table);
19131914
} else {
19141915
$.each(this.table, function (index, data) {
1915-
console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
1916+
console.log(data['Name'] + ': ' + data['Execution Time'] + 'ms');
19161917
});
19171918
}
19181919

@@ -1929,14 +1930,12 @@
19291930
};
19301931
// {/debug}
19311932

1932-
String.prototype.capitalize = function() {
1933+
String.prototype.capitalize = function () {
19331934
return this.charAt(0).toUpperCase() + this.slice(1);
19341935
};
19351936

1936-
if (!Array.prototype.indexOf)
1937-
{
1938-
Array.prototype.indexOf = function(elt /*, from*/)
1939-
{
1937+
if (!Array.prototype.indexOf) {
1938+
Array.prototype.indexOf = function (elt /*, from*/) {
19401939
var len = this.length >>> 0;
19411940

19421941
var from = Number(arguments[1]) || 0;
@@ -1946,8 +1945,7 @@
19461945
if (from < 0)
19471946
from += len;
19481947

1949-
for (; from < len; from++)
1950-
{
1948+
for (; from < len; from++) {
19511949
if (from in this &&
19521950
this[from] === elt)
19531951
return from;

0 commit comments

Comments
 (0)