aurelia / validation

A validation plugin for Aurelia.
MIT License
132 stars 128 forks source link

Bug? I can enter spaces as first characters when using .canBeEmpty().containsNoSpaces() #120

Closed valichek closed 8 years ago

valichek commented 9 years ago

When I start with entering spaces it validates to true until I enter "not space" char.

validation.on(target).ensure('contact.password').canBeEmpty().containsNoSpaces()
janvanderhaegen commented 9 years ago

The isNotEmpty (or the inverse: canBeEmpty) is evaluated before any other rule. However we do trim strings before evaluating if they are an 'empty' value, so your ' ' is considered empty and thus valid, until you type a non-space char and it starts evaluating the other rules (containsNoSpaces).

Not sure how we can change this without breaking the api,

ensure('firstname').isNotEmpty().hasMaxLength(3)

This would consider ' ' to be valid, although it's really not what you want the user to be able to enter as a first name.

We could add overloads isNotEmptyOrWhitespace and canBeEmptyOrWhitespace...

OTOH I can assume many people will prefer 'isNotEmpty()' to check for isNotEmptyOrWhitespace by default.

Thoughts?

plwalters commented 8 years ago

Thanks for submitting this / commenting on this. At this time we are closing this because we have completely re-written and are deprecating the previous feature set. If you feel this should be re-opened please feel free to review this blog post and submit either again on this repository, or on the new validatejs bridge repository

Thanks again!