From 5b3c7062d460d4f965b3b249d86319746168022f Mon Sep 17 00:00:00 2001 From: Stuart Yamartino Date: Tue, 22 May 2018 11:23:41 -0400 Subject: [PATCH] 0.0.8 currency and decimal --- dist/simple-react-validator.js | 6 ++++++ dist/simple-react-validator.min.js | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dist/simple-react-validator.js b/dist/simple-react-validator.js index 2bfd6e9..bdab0ac 100644 --- a/dist/simple-react-validator.js +++ b/dist/simple-react-validator.js @@ -46,6 +46,12 @@ var SimpleReactValidator = function () { card_num: { message: 'The :attribute must be a valid credit card number.', rule: function rule(val) { return _this._testRegex(val, /^\d{4}\s?\d{4,6}\s?\d{4,5}\s?\d{0,8}$/); } }, + currency: { message: 'The :attribute must be a valid currency.', rule: function rule(val) { + return _this._testRegex(val, /^\$?(\d{1,3}(\,?\d{3}))*\.?\d{0,2}$/); + } }, + decimal: { message: 'The :attribute must be a valid decimal.', rule: function rule(val) { + return _this._testRegex(val, /^\d*\.?\d*$/); + } }, email: { message: 'The :attribute must be a valid email address.', rule: function rule(val) { return _this._testRegex(val, /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i); } }, diff --git a/dist/simple-react-validator.min.js b/dist/simple-react-validator.min.js index d091dc5..db6c53e 100644 --- a/dist/simple-react-validator.min.js +++ b/dist/simple-react-validator.min.js @@ -1,2 +1,2 @@ // Simple React Validator v0.0.5 | 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,n),this.fields={},this.errorMessages={},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)}}},s)}return s(n,[{key:"getErrorMessages",value:function(){return this.errorMessages}},{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(!1===this.fieldValid(e))return!1;return!0}},{key:"fieldValid",value:function(e){return this.fields.hasOwnProperty(e)&&!0===this.fields[e]}},{key:"customMessage",value:function(e,t){if(e&&this.messagesShown)return this._reactErrorElement(e,t)}},{key:"message",value:function(e,t,r,s){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};this.errorMessages[e]=null,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,s)}},{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)}}]),n}()}); \ No newline at end of file +!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,n),this.fields={},this.errorMessages={},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}$/)}},currency:{message:"The :attribute must be a valid currency.",rule:function(t){return e._testRegex(t,/^\$?(\d{1,3}(\,?\d{3}))*\.?\d{0,2}$/)}},decimal:{message:"The :attribute must be a valid decimal.",rule:function(t){return e._testRegex(t,/^\d*\.?\d*$/)}},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)}}},s)}return s(n,[{key:"getErrorMessages",value:function(){return this.errorMessages}},{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(!1===this.fieldValid(e))return!1;return!0}},{key:"fieldValid",value:function(e){return this.fields.hasOwnProperty(e)&&!0===this.fields[e]}},{key:"customMessage",value:function(e,t){if(e&&this.messagesShown)return this._reactErrorElement(e,t)}},{key:"message",value:function(e,t,r,s){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};this.errorMessages[e]=null,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,s)}},{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)}}]),n}()}); \ No newline at end of file diff --git a/package.json b/package.json index 3fa63a8..0ec935b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-react-validator", - "version": "0.0.7", + "version": "0.0.8", "description": "A simple react form validator inspired by Laravel validation.", "main": "dist/simple-react-validator.min.js", "dependencies": {},