|
|
@ -698,40 +698,77 @@ $.fn.form.settings = { |
|
|
|
}, |
|
|
|
|
|
|
|
rules: { |
|
|
|
|
|
|
|
// checkbox checked
|
|
|
|
checked: function() { |
|
|
|
return ($(this).filter(':checked').size() > 0); |
|
|
|
}, |
|
|
|
empty: function(value) { |
|
|
|
return !(value === undefined || '' === value); |
|
|
|
|
|
|
|
// value contains (text)
|
|
|
|
contains: function(value, text) { |
|
|
|
text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); |
|
|
|
return (value.search(text) !== -1); |
|
|
|
}, |
|
|
|
|
|
|
|
// is most likely an email
|
|
|
|
email: function(value){ |
|
|
|
var |
|
|
|
emailRegExp = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", "i") |
|
|
|
; |
|
|
|
return emailRegExp.test(value); |
|
|
|
}, |
|
|
|
length: function(value, requiredLength) { |
|
|
|
return (value !== undefined) |
|
|
|
? (value.length >= requiredLength) |
|
|
|
: false |
|
|
|
; |
|
|
|
}, |
|
|
|
not: function(value, notValue) { |
|
|
|
return (value != notValue); |
|
|
|
|
|
|
|
// is not empty or blank string
|
|
|
|
empty: function(value) { |
|
|
|
return !(value === undefined || '' === value); |
|
|
|
}, |
|
|
|
contains: function(value, text) { |
|
|
|
text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); |
|
|
|
return (value.search(text) !== -1); |
|
|
|
|
|
|
|
// is valid integer
|
|
|
|
integer: function(value, range) { |
|
|
|
var |
|
|
|
intRegExp = /^\-?\d+$/, |
|
|
|
min, |
|
|
|
max, |
|
|
|
parts |
|
|
|
; |
|
|
|
if (range === undefined || range === '' || range === '..') { |
|
|
|
// do nothing
|
|
|
|
} |
|
|
|
else if (range.indexOf('..') == -1) { |
|
|
|
if (intRegExp.test(range)) { |
|
|
|
min = max = range - 0; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
parts = range.split('..', 2); |
|
|
|
if (intRegExp.test(parts[0])) { |
|
|
|
min = parts[0] - 0; |
|
|
|
} |
|
|
|
if (intRegExp.test(parts[1])) { |
|
|
|
max = parts[1] - 0; |
|
|
|
} |
|
|
|
} |
|
|
|
return ( |
|
|
|
intRegExp.test(value) && |
|
|
|
(min === undefined || value >= min) && |
|
|
|
(max === undefined || value <= max) |
|
|
|
); |
|
|
|
}, |
|
|
|
|
|
|
|
// is exactly value
|
|
|
|
is: function(value, text) { |
|
|
|
return (value == text); |
|
|
|
}, |
|
|
|
maxLength: function(value, maxLength) { |
|
|
|
|
|
|
|
// is at least string length
|
|
|
|
length: function(value, requiredLength) { |
|
|
|
return (value !== undefined) |
|
|
|
? (value.length <= maxLength) |
|
|
|
? (value.length >= requiredLength) |
|
|
|
: false |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
// matches another field
|
|
|
|
match: function(value, fieldIdentifier) { |
|
|
|
// use either id or name of field
|
|
|
|
var |
|
|
@ -752,41 +789,26 @@ $.fn.form.settings = { |
|
|
|
: false |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
// string length is less than max length
|
|
|
|
maxLength: function(value, maxLength) { |
|
|
|
return (value !== undefined) |
|
|
|
? (value.length <= maxLength) |
|
|
|
: false |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
// value is not exactly notValue
|
|
|
|
not: function(value, notValue) { |
|
|
|
return (value != notValue); |
|
|
|
}, |
|
|
|
|
|
|
|
// value is most likely url
|
|
|
|
url: function(value) { |
|
|
|
var |
|
|
|
urlRegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/ |
|
|
|
; |
|
|
|
return urlRegExp.test(value); |
|
|
|
}, |
|
|
|
integer: function(value, range) { |
|
|
|
var |
|
|
|
intRegExp = /^\-?\d+$/, |
|
|
|
min, |
|
|
|
max, |
|
|
|
parts |
|
|
|
; |
|
|
|
if (range === undefined || range === '' || range === '..') { |
|
|
|
// do nothing
|
|
|
|
} |
|
|
|
else if (range.indexOf('..') == -1) { |
|
|
|
if (intRegExp.test(range)) { |
|
|
|
min = max = range - 0; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
parts = range.split('..', 2); |
|
|
|
if (intRegExp.test(parts[0])) { |
|
|
|
min = parts[0] - 0; |
|
|
|
} |
|
|
|
if (intRegExp.test(parts[1])) { |
|
|
|
max = parts[1] - 0; |
|
|
|
} |
|
|
|
} |
|
|
|
return ( |
|
|
|
intRegExp.test(value) && |
|
|
|
(min === undefined || value >= min) && |
|
|
|
(max === undefined || value <= max) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|