Skip to content

Commit 1c0e9de

Browse files
committed
Conflicts: jquery.validation.js Added NAME rule
2 parents fa274b1 + cda88af commit 1c0e9de

File tree

4 files changed

+61
-70
lines changed

4 files changed

+61
-70
lines changed

demo/jquery.validation.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ div.error,
372372
div.error-list,
373373
label.error,
374374
input.error,
375-
select.error {
375+
select.error,
376+
textarea.error {
376377
color: #D95C5C !important;
377378
border-color: #D95C5C !important;
378379
}

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: 56 additions & 63 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,8 +39,9 @@
3839
var _rules = {
3940
NOTEMPTY: /\S/,
4041
INTEGER: /^\d+$/,
41-
NUMERIC: /^\d+(?:[,|\s]\d{3})?(?:\.\d+)?$/,
42-
MIXED: /^['\w\s-]+$/,
42+
NUMERIC: /^\d+(?:[,\s]\d{3})*(?:\.\d+)?$/,
43+
MIXED: /^[\w\s-]+$/,
44+
NAME: /^['a-z\s-]+$/i,
4345
NOSPACE: /^(?!\s)\S*$/,
4446
TRIM: /^[^\s].*[^\s]$/,
4547
DATE: /^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}(:\d{2})?)?$/,
@@ -57,12 +59,12 @@
5759
_messages = {
5860
'default': '$ contain error(s).',
5961
'NOTEMPTY': '$ must not be empty.',
60-
'NUMERIC': '$ must be numeric.',
6162
'INTEGER': '$ must be an integer.',
62-
'STRING': '$ must be a string.',
63+
'NUMERIC': '$ must be numeric.',
64+
'MIXED': '$ must be letters or numbers (no special characters).',
65+
'NAME': '$ must not contain special characters.',
6366
'NOSPACE': '$ must not contain spaces.',
6467
'TRIM': '$ must not start or end with space character.',
65-
'MIXED': '$ must be letters or numbers (no special characters).',
6668
'DATE': '$ is not a valid with format YYYY-MM-DD.',
6769
'EMAIL': '$ is not valid.',
6870
'URL': '$ is not valid.',
@@ -185,7 +187,7 @@
185187
/**
186188
* Extends user-defined "options.message" into the default Validation "_message".
187189
*/
188-
function extendRules () {
190+
function extendRules() {
189191
options.rules = $.extend(
190192
true,
191193
{},
@@ -197,7 +199,7 @@
197199
/**
198200
* Extends user-defined "options.message" into the default Validation "_message".
199201
*/
200-
function extendMessages () {
202+
function extendMessages() {
201203
options.messages = $.extend(
202204
true,
203205
{},
@@ -212,7 +214,7 @@
212214
* - preventExtensions prevents from modifying the Validation "_options" object structure
213215
* - filter through the "_supported" to delete unsupported "options"
214216
*/
215-
function extendOptions () {
217+
function extendOptions() {
216218

217219
if (!(options instanceof Object)) {
218220
options = {};
@@ -330,7 +332,7 @@
330332
});
331333
// {/debug}
332334

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

335337
// {debug}
336338
options.debug && window.Debug.log({
@@ -390,7 +392,7 @@
390392
* Delegates the submit validation on data-validation and data-validation-regex attributes based on trigger.
391393
* Note: Disable the form submit function so the callbacks are not by-passed
392394
*/
393-
function delegateValidation () {
395+
function delegateValidation() {
394396

395397
_executeCallback(options.submit.callback.onInit, [node]);
396398

@@ -462,12 +464,12 @@
462464
*
463465
* @returns {boolean} true if no error(s) were found (valid form)
464466
*/
465-
function validateForm () {
467+
function validateForm() {
466468

467469
var isValid = true;
468470

469471
$.each(
470-
node.find('[' + _data.validation + ']:not([disabled]),[' + _data.regex + ']:not([disabled])'),
472+
node.find('[' + _data.validation + ']:not([disabled],[readonly]),[' + _data.regex + ']:not([disabled],[readonly])'),
471473
function (index, input) {
472474
if (!validateInput(input)) {
473475
isValid = false;
@@ -487,7 +489,7 @@
487489
*
488490
* @returns {boolean} true if no error(s) were found (valid input)
489491
*/
490-
function validateInput (input) {
492+
function validateInput(input) {
491493

492494
var inputName = $(input).attr('name');
493495

@@ -529,7 +531,7 @@
529531
if (validationArray instanceof Array && validationArray.length > 0) {
530532

531533
// "OPTIONAL" input will not be validated if it's empty
532-
if (value === '' && $.inArray('OPTIONAL', validationArray) !== -1) {
534+
if (value === '' && ~validationArray.indexOf('OPTIONAL')) {
533535
return true;
534536
}
535537

@@ -597,7 +599,7 @@
597599
*
598600
* @returns {*} Error if a mismatch occurred.
599601
*/
600-
function validateRule (value, rule, reversed) {
602+
function validateRule(value, rule, reversed) {
601603

602604
// Validate for "data-validation-regex" and "data-validation-regex-reverse"
603605
if (rule instanceof RegExp) {
@@ -716,7 +718,7 @@
716718
* @param {string} inputName Input where the error occurred
717719
* @param {string} error Description of the error to be displayed
718720
*/
719-
function registerError (inputName, error) {
721+
function registerError(inputName, error) {
720722

721723
if (!errors[inputName]) {
722724
errors[inputName] = [];
@@ -747,7 +749,7 @@
747749
*
748750
* @returns {boolean} false if an unwanted behavior occurs
749751
*/
750-
function displayOneError (inputName) {
752+
function displayOneError(inputName) {
751753

752754
var input,
753755
inputId,
@@ -859,15 +861,15 @@
859861
}
860862
}
861863

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

864866
return function () {
865867
if (e) {
866868
if ($(c).hasClass(options.submit.settings.errorClass)) {
867-
resetOneError(a,b,c,d,e);
869+
resetOneError(a, b, c, d, e);
868870
}
869871
} else if ($(b).hasClass(options.submit.settings.errorClass)) {
870-
resetOneError(a,b,c,d);
872+
resetOneError(a, b, c, d);
871873
}
872874
};
873875

@@ -893,7 +895,7 @@
893895
/**
894896
* Display all of the errors
895897
*/
896-
function displayErrors () {
898+
function displayErrors() {
897899

898900
for (var inputName in errors) {
899901
if (!errors.hasOwnProperty(inputName)) continue;
@@ -959,7 +961,7 @@
959961
/**
960962
* Remove all of the input error(s) display.
961963
*/
962-
function resetErrors () {
964+
function resetErrors() {
963965

964966
errors = [];
965967
window.Validation.hasScrolled = false;
@@ -975,7 +977,7 @@
975977
* - This function will be overridden if "options.submit.settings.onSubmit" is defined
976978
* - The node can't be submitted by jQuery since it has been disabled, use the form native submit function instead
977979
*/
978-
function submitForm () {
980+
function submitForm() {
979981

980982
node[0].submit()
981983

@@ -986,7 +988,7 @@
986988
*
987989
* @returns {boolean}
988990
*/
989-
function destroy () {
991+
function destroy() {
990992

991993
resetErrors();
992994
node.find('[' + _data.validation + '],[' + _data.regex + ']').off(delegateSuffix + ' ' + resetSuffix);
@@ -1035,10 +1037,10 @@
10351037
* Execute function once the timer is reached.
10361038
* If the function is recalled before the timer ends, the first call will be canceled.
10371039
*/
1038-
var _typeWatch = (function(){
1040+
var _typeWatch = (function () {
10391041
var timer = 0;
1040-
return function(callback, ms){
1041-
clearTimeout (timer);
1042+
return function (callback, ms) {
1043+
clearTimeout(timer);
10421044
timer = setTimeout(callback, ms);
10431045
};
10441046
})();
@@ -1288,7 +1290,7 @@
12881290
rules = [rules];
12891291
}
12901292

1291-
for (var i=0; i<rules.length; i++) {
1293+
for (var i = 0; i < rules.length; i++) {
12921294
_api.alterValidationRules(rules[i]);
12931295
}
12941296

@@ -1480,7 +1482,7 @@
14801482
return false;
14811483
}
14821484

1483-
return node.each( function () {
1485+
return node.each(function () {
14841486

14851487
var $this = $(this),
14861488
validationData = $this.attr(_data.validation),
@@ -1521,7 +1523,7 @@
15211523
return false;
15221524
}
15231525

1524-
return node.each( function () {
1526+
return node.each(function () {
15251527

15261528
var $this = $(this),
15271529
validationData = $this.attr(_data.validation),
@@ -1618,15 +1620,15 @@
16181620
error[inputName] = [error[inputName]];
16191621
}
16201622

1621-
input = $(node.selector).find('[name="'+ inputName + '"]');
1623+
input = $(node.selector).find('[name="' + inputName + '"]');
16221624
if (!input[0]) {
16231625

16241626
// {debug}
16251627
window.Debug.log({
16261628
'node': node,
16271629
'function': '$.addError()',
16281630
'arguments': JSON.stringify(inputName),
1629-
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="'+ inputName + '"]")'
1631+
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="' + inputName + '"]")'
16301632
});
16311633

16321634
window.Debug.print();
@@ -1731,15 +1733,15 @@
17311733
var input;
17321734
for (var i = 0; i < inputName.length; i++) {
17331735

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

17371739
// {debug}
17381740
window.Debug.log({
17391741
'node': node,
17401742
'function': '$.removeError()',
17411743
'arguments': JSON.stringify(inputName[i]),
1742-
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="'+ inputName[i] + '"]")'
1744+
'message': 'ERROR - Unable to find ' + '$(' + node.selector + ').find("[name="' + inputName[i] + '"]")'
17431745
});
17441746

17451747
window.Debug.print();
@@ -1912,7 +1914,7 @@
19121914
console.table(this.table);
19131915
} else {
19141916
$.each(this.table, function (index, data) {
1915-
console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
1917+
console.log(data['Name'] + ': ' + data['Execution Time'] + 'ms');
19161918
});
19171919
}
19181920

@@ -1929,34 +1931,25 @@
19291931
};
19301932
// {/debug}
19311933

1932-
String.prototype.capitalize = function() {
1934+
String.prototype.capitalize = function () {
19331935
return this.charAt(0).toUpperCase() + this.slice(1);
19341936
};
19351937

19361938
if (!Array.prototype.indexOf) {
1937-
Array.prototype.indexOf = function(searchElement, fromIndex) {
1938-
var k;
1939-
if (this == null) {
1940-
throw new TypeError('"this" is null or not defined');
1941-
}
1942-
var O = Object(this);
1943-
var len = O.length >>> 0;
1944-
if (len === 0) {
1945-
return -1;
1946-
}
1947-
var n = +fromIndex || 0;
1948-
if (Math.abs(n) === Infinity) {
1949-
n = 0;
1950-
}
1951-
if (n >= len) {
1952-
return -1;
1953-
}
1954-
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
1955-
while (k < len) {
1956-
if (k in O && O[k] === searchElement) {
1957-
return k;
1958-
}
1959-
k++;
1939+
Array.prototype.indexOf = function (elt /*, from*/) {
1940+
var len = this.length >>> 0;
1941+
1942+
var from = Number(arguments[1]) || 0;
1943+
from = (from < 0)
1944+
? Math.ceil(from)
1945+
: Math.floor(from);
1946+
if (from < 0)
1947+
from += len;
1948+
1949+
for (; from < len; from++) {
1950+
if (from in this &&
1951+
this[from] === elt)
1952+
return from;
19601953
}
19611954
return -1;
19621955
};

0 commit comments

Comments
 (0)