Browse Source

Moves all regexp to a separate settings object

pull/2169/head
jlukic 9 years ago
parent
commit
f552fdb90f
1 changed files with 10 additions and 9 deletions
  1. 19
      src/definitions/behaviors/form.js

19
src/definitions/behaviors/form.js

@ -966,7 +966,11 @@ $.fn.form.settings = {
}, },
regExp: { regExp: {
bracket: /\[(.*)\]/i
bracket : /\[(.*)\]/i,
escape : /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,
email : "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
integer : /^\-?\d+$/,
url : /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i
}, },
selector : { selector : {
@ -1029,21 +1033,21 @@ $.fn.form.settings = {
// value contains text (insensitive) // value contains text (insensitive)
contains: function(value, text) { contains: function(value, text) {
// escape regex characters // escape regex characters
text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
text = text.replace($.fn.form.settings.regExp.escape, "\\$&");
return (value.search( new RegExp(text, 'i') ) !== -1); return (value.search( new RegExp(text, 'i') ) !== -1);
}, },
// value contains text (case sensitive) // value contains text (case sensitive)
containsExactly: function(value, text) { containsExactly: function(value, text) {
// escape regex characters // escape regex characters
text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
text = text.replace($.fn.form.settings.regExp.escape, "\\$&");
return (value.search( new RegExp(text) ) !== -1); return (value.search( new RegExp(text) ) !== -1);
}, },
// is most likely an email // is most likely an email
email: function(value){ email: function(value){
var 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')
emailRegExp = new RegExp($.fn.form.settings.regExp.email, 'i')
; ;
return emailRegExp.test(value); return emailRegExp.test(value);
}, },
@ -1056,7 +1060,7 @@ $.fn.form.settings = {
// is valid integer // is valid integer
integer: function(value, range) { integer: function(value, range) {
var var
intRegExp = /^\-?\d+$/,
intRegExp = $.fn.form.settings.regExp.integer,
min, min,
max, max,
parts parts
@ -1181,10 +1185,7 @@ $.fn.form.settings = {
// value is most likely url // value is most likely url
url: function(value) { url: function(value) {
var
urlRegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
;
return urlRegExp.test(value);
return $.fn.form.settings.regExp.url.match(value);
} }
} }

Loading…
Cancel
Save