Skip to content

Commit fda0218

Browse files
committed
Issue 166: URL regex in validator now allows "&" and "+" characters in query string
1 parent 9b59208 commit fda0218

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/validator/validator.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
// globals
1818
var typeRe = /\[type=([a-z]+)\]/,
1919
numRe = /^-?[0-9]*(\.[0-9]+)?$/,
20+
dateInput = $.tools.dateinput,
2021

2122
// http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
2223
emailRe = /^([a-z0-9_\.\-\+]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/i,
23-
urlRe = /^(https?:\/\/)?[\da-z\.\-]+\.[a-z\.]{2,6}[#\?\/\w \.\-=]*$/i,
24+
urlRe = /^(https?:\/\/)?[\da-z\.\-]+\.[a-z\.]{2,6}[#&+_\?\/\w \.\-=]*$/i,
2425
v;
2526

2627
v = $.tools.validator = {
@@ -224,7 +225,7 @@
224225
v.fn("[max]", "Please enter a value smaller than $1", function(el, v) {
225226

226227
// skip empty values and dateinputs
227-
if (v === '' || $.tools.dateinput && el.is(":date")) { return true; }
228+
if (v === '' || dateInput && el.is(":date")) { return true; }
228229

229230
var max = el.attr("max");
230231
return parseFloat(v) <= parseFloat(max) ? true : [max];
@@ -233,7 +234,7 @@
233234
v.fn("[min]", "Please enter a value larger than $1", function(el, v) {
234235

235236
// skip empty values and dateinputs
236-
if (v === '' || $.tools.dateinput && el.is(":date")) { return true; }
237+
if (v === '' || dateInput && el.is(":date")) { return true; }
237238

238239
var min = el.attr("min");
239240
return parseFloat(v) >= parseFloat(min) ? true : [min];
@@ -396,7 +397,7 @@
396397
// field and it's error message container
397398
var msgs = [],
398399
el = $(this).data("messages", msgs),
399-
event = el.is(":date") ? "onHide.v" : conf.errorInputEvent + ".v";
400+
event = dateInput && el.is(":date") ? "onHide.v" : conf.errorInputEvent + ".v";
400401

401402
// cleanup previous validation event
402403
el.unbind(event);

test/validator/minimal.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<label>
4141
URL
42-
<input type="url" value="http://www.spa.gov.sa/NewsHeadlines.php?pg=2" />
42+
<input type="url" value="http://www.spa.gov.sa/NewsHeadlines.php?pg=2&joku+paha" />
4343
</label>
4444

4545
<label>

0 commit comments

Comments
 (0)