validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Exception while using any for isMobilePhone validation

Open AnkurThakur opened this issue 9 years ago • 1 comments

Hi,

When I'm trying to use any(#663) in the isMobilePhone validation, it throws me a TypeError. Please see the example below:

var validator = require('validator'); console.log("Mobile Valid", validator.isMobilePhone("+16173324656", "any")); It throws a TypeError:

D:\Exsete\Projects\NodeJS\validator\node_modules\validator\lib\isMobilePhone.js:75
    return !!Object.values(phones).find(function (phone) {
                    ^
TypeError: Object.values is not a function
    at Object.isMobilePhone (D:\Exsete\Projects\NodeJS\validator\node_modules\validator\lib\isMobilePhone.js:75:21)
    at Object.<anonymous> (D:\Exsete\Projects\NodeJS\validator\index.js:5:39)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)

But, individually when you will try en-US in place of that, it works.

Windows with Node 6.11.0: Doesn't work Debian 7 Wheezy with Node 8.4.0: Works

So, what I concluded from this answer is that it requires the latest node version. We should mention it somewhere as I got to know about this problem when my code broke in the production environment.

AnkurThakur avatar Aug 21 '17 06:08 AnkurThakur

Dupe: https://github.com/chriso/validator.js/issues/681

chriso avatar Aug 22 '17 08:08 chriso