How to pass a locale to Validator.isMobilePhone?

Asked

Viewed 48 times

-3

As step one locale pt-BR to the validator.isMobilePhone in my Mongoose schema? According to the documentation I should use an array, something similar to the code below, but the program gives error when compiling.

  phone: {
    type: String,
    required: [true, 'Por favor, forneça seu telefone.'],
    validate: [
      validator.isMobilePhone(options: ['pt-BR']),
      'Favor fornecer um telefone válido.'
    ]
  }

1 answer

-1

I re-wrote the code that way:

  phone: {
    type: String,
    required: [true, 'Por favor, forneça seu telefone.'],
    validate: {
      validator: function(v) {
        return validator.isMobilePhone(v, 'pt-BR');
      },
      message: props => `${props.value} não é um telefone válido.`
    }
  },

Browser other questions tagged

You are not signed in. Login or sign up in order to post.