diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index 2b413a597..8f84b1b91 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -1051,11 +1051,42 @@ $.fn.form.settings = { rules: { + // is not empty or blank string + empty: function(value) { + return !(value === undefined || '' === value || $.isArray(value) && value.length === 0); + }, + // checkbox checked checked: function() { return ($(this).filter(':checked').length > 0); }, + // is most likely an email + email: function(value){ + var + emailRegExp = new RegExp($.fn.form.settings.regExp.email, 'i') + ; + return emailRegExp.test(value); + }, + + // is value (case insensitive) + is: function(value, text) { + text = (typeof text == 'string') + ? text.toLowerCase() + : text + ; + value = (typeof value == 'string') + ? value.toLowerCase() + : value + ; + return (value == text); + }, + + // is value + isExactly: function(value, text) { + return (value == text); + }, + // value contains text (insensitive) contains: function(value, text) { // escape regex characters @@ -1070,17 +1101,36 @@ $.fn.form.settings = { return (value.search( new RegExp(text) ) !== -1); }, - // is most likely an email - email: function(value){ - var - emailRegExp = new RegExp($.fn.form.settings.regExp.email, 'i') + // value contains text (insensitive) + doesntContain: function(value, text) { + // escape regex characters + text = text.replace($.fn.form.settings.regExp.escape, "\\$&"); + return (value.search( new RegExp(text, 'i') ) === -1); + }, + + // value contains text (case sensitive) + doesntContainExactly: function(value, text) { + // escape regex characters + text = text.replace($.fn.form.settings.regExp.escape, "\\$&"); + return (value.search( new RegExp(text) ) === -1); + }, + + // value is not value (case insensitive) + not: function(value, notValue) { + value = (typeof value == 'string') + ? value.toLowerCase() + : value ; - return emailRegExp.test(value); + notValue = (typeof notValue == 'string') + ? notValue.toLowerCase() + : notValue + ; + return (value != notValue); }, - // is not empty or blank string - empty: function(value) { - return !(value === undefined || '' === value || $.isArray(value) && value.length === 0); + // value is not value (case sensitive) + notExactly: function(value, notValue) { + return (value != notValue); }, // is valid integer @@ -1115,24 +1165,6 @@ $.fn.form.settings = { ); }, - // is value (case insensitive) - is: function(value, text) { - text = (typeof text == 'string') - ? text.toLowerCase() - : text - ; - value = (typeof value == 'string') - ? value.toLowerCase() - : value - ; - return (value == text); - }, - - // is value - isExactly: function(value, text) { - return (value == text); - }, - // is at least string length length: function(value, requiredLength) { return (value !== undefined) @@ -1248,24 +1280,6 @@ $.fn.form.settings = { ; }, - // value is not value (case insensitive) - not: function(value, notValue) { - value = (typeof value == 'string') - ? value.toLowerCase() - : value - ; - notValue = (typeof notValue == 'string') - ? notValue.toLowerCase() - : notValue - ; - return (value != notValue); - }, - - // value is not value (case sensitive) - notExactly: function(value, notValue) { - return (value != notValue); - }, - // value is most likely url url: function(value) { return $.fn.form.settings.regExp.url.test(value);