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

Integer validation passes fractions #233

Closed AbdelrahmanHafez closed 6 years ago

AbdelrahmanHafez commented 6 years ago

    let expectedBody = {
      user: {
        name: {
          first: 'required|string',
          last: 'required|string'
        },
        username: 'required|string',
        password: 'required|string',
        email: 'required|email',
        mobile: 'required|integer'
      },
      holdingCompanyId: 'required|string'
    };

    let validation = new Validator(req.body, expectedBody);
    if (validation.fails()) return res.status(500).json({ case: 0, message: validation.errors.all() });

When I pass 1000.123 for the mobile field, it passes, I expected it to fail, since it's an integer.

vict-shevchenko commented 6 years ago

Here are results from running application that uses Validatorjs.

screen shot 2018-01-23 at 12 47 27 pm

a stands for Validator class. Code is minified.

So, I think you should double check your setup.

mikeerickson commented 6 years ago

@AbdelrahmanHafez As @vict-shevchenko has demonstrated, it should be working as developed. Could you create a pen (codepen.com, pastebin.com, etc) somewhere with any example code?

AbdelrahmanHafez commented 6 years ago

Woah, I just tested it, I could swear it didn't work earlier, now it works as expected, thanks a lot!