carvalhoviniciusluiz / cpf-cnpj-validator

Valida e formata strings de CPF ou CNPJ.
MIT License
207 stars 27 forks source link

Issue validating with spaces and letters #44

Open emafriedrich opened 3 months ago

emafriedrich commented 3 months ago

We have a issue regarding validations with strings that has spaces and letters

> const v = require('cpf-cnpj-validator')
> v.cpf.isValid('   16704533672     d ')
true
> v.cpf.isValid('   16704533672     ')
true
> v.cpf.isValid('   16704533672     asdfasdfasdf')
true
> v.cpf.isValid('   16704533672     asdfasdfasdf as34343434')
false
> v.cpf.isValid('   16704533672     asdfasdfasdf as3')
false
> v.cpf.isValid('   16704533672     asdfasdfasdf asasdfasdf asdfasdf asdf asdf asdfasdf')
true
> v.cpf.isValid('asdfasdf16704533672asdfasdf')
true

We consider this as a big issue. You will know if is intended this behavior.

Just to let you know.

Thanks

patrickJramos commented 3 months ago

isValid only validates the digits in the string by default.

If you need those to fail, you may send a second parameter called strict, for stricter validation. It will return false if there are any non-digit characters, except "." and "-", which are ignored.

example: v.cpf.isValid(value, false).