guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.04k stars 1.31k forks source link

allow data-parsley-length to equal exact length #669

Open attenzione opened 10 years ago

attenzione commented 10 years ago

this would helpful for me, if i could to like this data-parsley-length="10", corresponding message should be changed (This value length is invalid. It should be between %s and %s characters long. without between), but of course should keep both messages

i know, that i can create my validation, but i think it should be possible with build-in length validation

marcandre commented 9 years ago

Handling of error message is pretty simplistic, so that's not possible without a different validator. I would accept a PR for an exact-length validator, say, to be put in extra/validator if you feel up for it!

attenzione commented 9 years ago

I think you are wrong, because you allow exact length, but the message is incorrect

marcandre commented 9 years ago

:smile: The message is sounds odd for sure, but it isn't incorrect in the strictest sense. The issue is really that it's best to keep the error messages simple, for i18n & al. You realize that you can easily specify an error message for that particular field with parsley-length-error-message, right?

attenzione commented 9 years ago

Not exactly, but this solution could exist, like common, for all validators. But I thought about two different messages in i18n, validator choose, which one is displayed

marcandre commented 9 years ago

It's true that this already exists for type, so could be made more generic.

hansondr commented 9 years ago

@marcandre this is slightly off-topic, but how would you feel about having the length validator match exact length and create a new validator like length-range which would get length's current behavior?

Edit: Submitted a PR to ValidatorJS which demonstrates this