diff --git a/bower.json b/bower.json index 062c575..b7dcec7 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "simple-react-validator", "description": "A simple react form validator inspired by Laravel validation.", "main": "dist/simple-react-validator.min.js", - "version": "0.0.3", + "version": "0.0.4", "authors": [ "Stuart Yamartino" ], diff --git a/dist/simple-react-validator.js b/dist/simple-react-validator.js index 444bef0..98ee85b 100644 --- a/dist/simple-react-validator.js +++ b/dist/simple-react-validator.js @@ -1,4 +1,4 @@ -// Simple React Validator v0.0.3 | Created By Dockwa | MIT License | 2017 +// Simple React Validator v0.0.4 | Created By Dockwa | MIT License | 2017 ;(function(root, factory) { if (typeof define === 'function' && define.amd) { define(['react'], factory); diff --git a/dist/simple-react-validator.min.js b/dist/simple-react-validator.min.js index b7af9d1..4bbc9c2 100644 --- a/dist/simple-react-validator.min.js +++ b/dist/simple-react-validator.min.js @@ -1,2 +1,2 @@ -// Simple React Validator v0.0.3 | Created By Dockwa | MIT License | 2017 +// Simple React Validator v0.0.4 | Created By Dockwa | MIT License | 2017 !function(e,t){"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?module.exports=t(require("react")):e.SimpleReactValidator=t(e.React)}(this,function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:{};t(this,s),this.fields=[],this.messagesShown=!1,this.rules=r({accepted:{message:"The :attribute must be accepted.",rule:function(e){return!0===e}},alpha:{message:"The :attribute may only contain letters.",rule:function(t){return e._testRegex(t,/^[A-Z]*$/i)}},alpha_num:{message:"The :attribute may only contain letters and numbers.",rule:function(t){return e._testRegex(t,/^[A-Z0-9]*$/i)}},alpha_num_dash:{message:"The :attribute may only contain letters, numbers, and dashes.",rule:function(t){return e._testRegex(t,/^[A-Z0-9_-]*$/i)}},card_exp:{message:"The :attribute must be a valid expiration date.",rule:function(t){return e._testRegex(t,/^(([0]?[1-9]{1})|([1]{1}[0-2]{1}))\s?\/\s?(\d{2}|\d{4})$/)}},card_num:{message:"The :attribute must be a valid credit card number.",rule:function(t){return e._testRegex(t,/^\d{4}\s?\d{4,6}\s?\d{4,5}\s?\d{0,8}$/)}},email:{message:"The :attribute must be a valid email address.",rule:function(t){return e._testRegex(t,/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i)}},gt:{message:"The :attribute must be greater than :gt.",rule:function(t,r){return!!e._testRegex(t,/^\d+.?\d*$/)&&parseFloat(t)>parseFloat(r[0])},messageReplace:function(e,t){return e.replace(":gt",t[0])}},gte:{message:"The :attribute must be greater than or equal to :gte.",rule:function(t,r){return!!e._testRegex(t,/^\d+.?\d*$/)&&parseFloat(t)>=parseFloat(r[0])},messageReplace:function(e,t){return e.replace(":gte",t[0])}},in:{message:"The selected :attribute must be :values.",rule:function(e,t){return t.indexOf(e)>-1},messageReplace:function(t,r){return t.replace(":values",e._toSentence(r))}},integer:{message:"The :attribute must be an integer.",rule:function(t){return e._testRegex(t,/^\d+$/)}},lt:{message:"The :attribute must be less than :lt.",rule:function(t,r){return!!e._testRegex(t,/^\d+.?\d*$/)&&parseFloat(t)=t[0]},messageReplace:function(e,t){return e.replace(":min",t[0])}},not_in:{message:"The selected :attribute must not be :values.",rule:function(e,t){return-1===t.indexOf(e)},messageReplace:function(t,r){return t.replace(":values",e._toSentence(r))}},numeric:{message:"The :attribute must be a number.",rule:function(t){return e._testRegex(t,/^\d+.?\d*$/)}},phone:{message:"The :attribute must be a valid phone number.",rule:function(t){return e._testRegex(t,/(\+?\d{0,4})?\s?-?\s?(\(?\d{3}\)?)\s?-?\s?(\(?\d{3}\)?)\s?-?\s?(\(?\d{4}\)?)/)}},required:{message:"The :attribute field is required.",rule:function(t){return e._testRegex(t,/.+/)}},url:{message:"The :attribute must be a url.",rule:function(t){return e._testRegex(t,/^(https?|ftp):\/\/(-\.)?([^\s\/?\.#-]+\.?)+(\/[^\s]*)?$/i)}}},n)}return n(s,[{key:"showMessages",value:function(){this.messagesShown=!0}},{key:"hideMessages",value:function(){this.messagesShown=!1}},{key:"allValid",value:function(){for(var e in this.fields)if(this.fields.hasOwnProperty(e)&&!1===this.fields[e])return!1;return!0}},{key:"customMessage",value:function(e,t){if(e&&this.messagesShown)return this._reactErrorElement(e,t)}},{key:"message",value:function(e,t,r,n){var s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};this.fields[e]=!0;for(var a,u,i,l=r.split("|"),o=0;o0&&this.rules[a].hasOwnProperty("messageReplace")?this._reactErrorElement(this.rules[a].messageReplace(i,u)):this._reactErrorElement(i,n)}},{key:"_getRule",value:function(e){return e.split(":")[0]}},{key:"_getOptions",value:function(e){var t=e.split(":");return t.length>1?t[1].split(","):[]}},{key:"_valueOrEmptyString",value:function(e){return void 0===e||null===e?"":e}},{key:"_toSentence",value:function(e){return e.slice(0,-2).join(", ")+(e.slice(0,-2).length?", ":"")+e.slice(-2).join(e.length>2?", or ":" or ")}},{key:"_reactErrorElement",value:function(t,r){return e.createElement("div",{className:r||"validation-message"},t)}},{key:"_testRegex",value:function(e,t){return null!==e.toString().match(t)}}]),s}()}); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 45f1261..624575f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,7 @@ var inject = require('gulp-inject-string') var rename = require('gulp-rename'); var uglify = require('gulp-uglify'); var babel = require('gulp-babel'); -var HEADER_COMMENT = '// Simple React Validator v0.0.3 | Created By Dockwa | MIT License | 2017\n'; +var HEADER_COMMENT = '// Simple React Validator v0.0.4 | Created By Dockwa | MIT License | 2017\n'; var gutil = require('gulp-util'); diff --git a/package.json b/package.json index e79c0ee..137d697 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-react-validator", - "version": "0.0.3", + "version": "0.0.4", "description": "A simple react form validator inspired by Laravel validation.", "main": "dist/simple-react-validator.min.js", "dependencies": {}, diff --git a/src/simple-react-validator.js b/src/simple-react-validator.js index 09cdb5e..75eb158 100644 --- a/src/simple-react-validator.js +++ b/src/simple-react-validator.js @@ -66,8 +66,8 @@ class SimpleReactValidator{ this.fields[field] = false; if(this.messagesShown){ message = customErrors[rule] || - customErrors.default || - this.rules[rule].message.replace(':attribute', field.replace(/_/g, ' ')); + customErrors.default || + this.rules[rule].message.replace(':attribute', field.replace(/_/g, ' ')); if(options.length > 0 && this.rules[rule].hasOwnProperty('messageReplace')){ return this._reactErrorElement(this.rules[rule].messageReplace(message, options)); @@ -106,4 +106,4 @@ class SimpleReactValidator{ _testRegex(value, regex){ return value.toString().match(regex) !== null; } -} \ No newline at end of file +}