Skip to content

Commit bb14ad0

Browse files
authored
Improve Url regex and add check (#179)
1 parent 2d5d82d commit bb14ad0

19 files changed

+95
-31
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ constructor() {
159159

160160
`messageWhenPresent(message, options = {})` Show a message when the message is set, good for ajax validation errors.
161161

162-
`message(field, inputValue, validations, options = {})` How you define validation rules and add messages into the form.
162+
`check(value, validations)` A simple way of checking a value against a built in validation rule. Does not add to the validator, just gives a true / false return value.
163+
164+
`message(field, value, validations, options = {})` How you define validation rules and add messages into the form.
163165

164166
## onBlur
165167

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "simple-react-validator",
33
"description": "A simple react form validator inspired by Laravel validation.",
44
"main": "dist/simple-react-validator.min.js",
5-
"version": "1.3.2",
5+
"version": "1.4.0",
66
"authors": [
77
"Stuart Yamartino"
88
],

dist/locale/es.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Simple React Validator v1.3.2 | Created By Dockwa | MIT License | 2017 - Present
1+
// Simple React Validator v1.4.0 | Created By Dockwa | MIT License | 2017 - Present
22
;(function(root, factory) {
33
if (typeof define === 'function' && define.amd) {
44
define(['simple-react-validator'], factory);

dist/locale/fa.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Simple React Validator v1.3.2 | Created By Dockwa | MIT License | 2017 - Present
1+
// Simple React Validator v1.4.0 | Created By Dockwa | MIT License | 2017 - Present
22
;(function(root, factory) {
33
if (typeof define === 'function' && define.amd) {
44
define(['simple-react-validator'], factory);

dist/locale/fr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Simple React Validator v1.3.2 | Created By Dockwa | MIT License | 2017 - Present
1+
// Simple React Validator v1.4.0 | Created By Dockwa | MIT License | 2017 - Present
22
;(function(root, factory) {
33
if (typeof define === 'function' && define.amd) {
44
define(['simple-react-validator'], factory);

dist/locale/min/es.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/locale/min/fa.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/locale/min/fr.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/locale/min/sr.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/locale/min/template-en.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/locale/sr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Simple React Validator v1.3.2 | Created By Dockwa | MIT License | 2017 - Present
1+
// Simple React Validator v1.4.0 | Created By Dockwa | MIT License | 2017 - Present
22
;(function(root, factory) {
33
if (typeof define === 'function' && define.amd) {
44
define(['simple-react-validator'], factory);

dist/locale/template-en.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Simple React Validator v1.3.2 | Created By Dockwa | MIT License | 2017 - Present
1+
// Simple React Validator v1.4.0 | Created By Dockwa | MIT License | 2017 - Present
22
;(function(root, factory) {
33
if (typeof define === 'function' && define.amd) {
44
define(['simple-react-validator'], factory);

dist/simple-react-validator.js

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Simple React Validator v1.3.2 | Created By Dockwa | MIT License | 2017 - Present
1+
// Simple React Validator v1.4.0 | Created By Dockwa | MIT License | 2017 - Present
22
;(function(root, factory) {
33
if (typeof define === 'function' && define.amd) {
44
define(['react'], factory);
@@ -407,7 +407,7 @@ function () {
407407
url: {
408408
message: 'The :attribute must be a url.',
409409
rule: function rule(val) {
410-
return _this.helpers.testRegex(val, /^(https?|ftp):\/\/(-\.)?([^\s/?\.#-]+\.?)+(\/[^\s]*)?$/i);
410+
return _this.helpers.testRegex(val, /^https?:\/\/[-a-z0-9@:%._\+~#=]{1,256}\.[a-z0-9()]{2,6}\b([-a-z0-9()@:%_\+.~#?&//=]*)$/i);
411411
}
412412
}
413413
}, _options.validators || {}); // apply language
@@ -503,11 +503,9 @@ function () {
503503
}
504504
}
505505
}, {
506-
key: "message",
507-
value: function message(field, inputValue, validations) {
508-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
509-
this.errorMessages[field] = null;
510-
this.fields[field] = true;
506+
key: "check",
507+
value: function check(inputValue, validations) {
508+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
511509

512510
if (!Array.isArray(validations)) {
513511
validations = validations.split('|');
@@ -528,6 +526,53 @@ function () {
528526
rule = _this$helpers$normali2[1],
529527
params = _this$helpers$normali2[2];
530528

529+
if (!this.helpers.passes(rule, value, params, rules)) {
530+
return false;
531+
}
532+
}
533+
} catch (err) {
534+
_didIteratorError = true;
535+
_iteratorError = err;
536+
} finally {
537+
try {
538+
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
539+
_iterator["return"]();
540+
}
541+
} finally {
542+
if (_didIteratorError) {
543+
throw _iteratorError;
544+
}
545+
}
546+
}
547+
548+
return true;
549+
}
550+
}, {
551+
key: "message",
552+
value: function message(field, inputValue, validations) {
553+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
554+
this.errorMessages[field] = null;
555+
this.fields[field] = true;
556+
557+
if (!Array.isArray(validations)) {
558+
validations = validations.split('|');
559+
}
560+
561+
var rules = options.validators ? _objectSpread({}, this.rules, {}, options.validators) : this.rules;
562+
var _iteratorNormalCompletion2 = true;
563+
var _didIteratorError2 = false;
564+
var _iteratorError2 = undefined;
565+
566+
try {
567+
for (var _iterator2 = validations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
568+
var validation = _step2.value;
569+
570+
var _this$helpers$normali3 = this.helpers.normalizeValues(inputValue, validation),
571+
_this$helpers$normali4 = _slicedToArray(_this$helpers$normali3, 3),
572+
value = _this$helpers$normali4[0],
573+
rule = _this$helpers$normali4[1],
574+
params = _this$helpers$normali4[2];
575+
531576
if (!this.helpers.passes(rule, value, params, rules)) {
532577
this.fields[field] = false;
533578
var message = this.helpers.message(rule, field, options, rules);
@@ -544,16 +589,16 @@ function () {
544589
}
545590
}
546591
} catch (err) {
547-
_didIteratorError = true;
548-
_iteratorError = err;
592+
_didIteratorError2 = true;
593+
_iteratorError2 = err;
549594
} finally {
550595
try {
551-
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
552-
_iterator["return"]();
596+
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
597+
_iterator2["return"]();
553598
}
554599
} finally {
555-
if (_didIteratorError) {
556-
throw _iteratorError;
600+
if (_didIteratorError2) {
601+
throw _iteratorError2;
557602
}
558603
}
559604
}

0 commit comments

Comments
 (0)