mikeerickson / validatorjs

A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
https://www.npmjs.com/package/validatorjs
MIT License
1.77k stars 280 forks source link

Rule 'digits' allows spaces #322

Open kculmback opened 5 years ago

kculmback commented 5 years ago

Using the rule 'digits:5' as part of validating zip codes. When testing, the rule allows for spaces in the zip code, which it shouldn't. For example 9980 passes validation.

mikeerickson commented 3 years ago

Available in current release

amal-chacko-7 commented 3 years ago

@mikeerickson @igor875126 trim() function not defined for integer values. (node:7608) UnhandledPromiseRejectionWarning: TypeError: val.trim is not a function at Rule.digits [as fn] (F:\Workspace\node-barebone\node_modules\validatorjs\src\rules.js:376:49) at Rule._apply (F:\Workspace\node-barebone\node_modules\validatorjs\src\rules.js:634:15) at Rule.validate (F:\Workspace\node-barebone\node_modules\validatorjs\src\rules.js:616:36) at F:\Workspace\node-barebone\node_modules\validatorjs\src\validator.js:114:14 at Validator.checkAsync (F:\Workspace\node-barebone\node_modules\validatorjs\src\validator.js:137:63) at Validator.passes (F:\Workspace\node-barebone\node_modules\validatorjs\src\validator.js:495:19) at validator (F:\Workspace\node-barebone\lib\validator.js:4:14) at signup (F:\Workspace\node-barebone\validation\customer\customer_auth.js:12:9) at Layer.handle [as handle_request] (F:\Workspace\node-barebone\node_modules\express\lib\router\layer.js:95:5) at next (F:\Workspace\node-barebone\node_modules\express\lib\router\route.js:137:13) (Usenode --trace-warnings ...to show where the warning was created) (node:7608) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:7608) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

markwbrown commented 3 years ago

I can confirm the trim() function not defined for integer values @amal-chacko-7 has reported. Looks like this needs more work. @mikeerickson request reopen

mikeerickson commented 3 years ago

@markwbrown i have reopened this issue and will look closer into get this resolved internally. We are preparing a new version and will see to it that this issue is resolved according