validatorjs / validator.js

String validation
MIT License
23.12k stars 2.31k forks source link

add more options in isLength - feature request #1937

Open guicompeng opened 2 years ago

guicompeng commented 2 years ago

Currently the options for isLength are min and max only. I believe there could be more options. I'm needing the field size to be exactly 11 or 14 or 16. For now I'm using min 11 and max 16 but in my program the length values (12, 13, 15) should not be accepted. a new option can be:

exact: {11, 14, 16} or size: {11, 14, 16}

Do you think this change adding more options would be a good thing?

Carlos-Gaxiola commented 2 years ago

Hello, as a user, I think this is a really useful feature, I am currently working in this issue, to create a function that does this, I will create a Pull Request later when I complete the feature :)

bevatsal1122 commented 2 years ago

Hello, I have added the required feature. If the string length falls in the range and if exact number/array/object is mentioned, then exact conditions are checked. If not provided, then true is returned is len>=min & len<=max and false is returned is not in range [min, max]. Thanks for giving me a chance to contribute :) PR#2019 - https://github.com/validatorjs/validator.js/pull/2019

bevatsal1122 commented 2 years ago

Heyy @rubiin !! This additional feature is been added in PR https://github.com/validatorjs/validator.js/pull/2019. It would be great if you could have a look.

NwaforAugustine321 commented 1 year ago

@guicompeng I want to know if this issue is still open for me to work on it. Thanks and look forward to hearing from you.