All range validations are not firing on the client side

May 2, 2011 at 10:26 PM

Hi,

I am trying to use Fluent Validation for one of our MVC projects, and I am not able to get range validation (LessThanOrEqualTo, LessThan, GreaterThan, InclusiveBetween, etc) working on the client side, other validations are working fine on the client side and server side.

Any help would be appreciated.

TIA

~ Sagar

Coordinator
May 3, 2011 at 5:58 AM

Hi

These validators are not supported on the client. The only validators that are client-side enabled out of the box are those that directly correspond to MVC's built-in client-side validators. In FluentValidation v2, we support 3 of these:

  • NotNull/NotEmpty
  • Length/ExactLength
  • Matches (regex)

FluentValidation v3 will also be adding support for a few others:

  • Range validation with InclusiveBetween (note that GreaterThan/LessThan etc are not used for ranges) 
  • Credit card
  • Email
  • Cross-property equal

Jeremy

May 3, 2011 at 4:23 PM

Hi Jeremy,

Thanks for the response. Can you please let us know the release date of v3 ? In the mean time, do we have any extension point where I can add client side validation for range validators ?

Thanks,

~ Sagar

Coordinator
May 3, 2011 at 4:51 PM

No release date for v3 yet...I'll probably be putting out the first beta in the next couple of weeks, but it depends on how much time I have available. Rather than waiting for a binary release, you can also build from source - it's available at https://github.com/JeremySkinner/FluentValidation and is already pretty stable.

If you want to stick with v2, then you can create a subclass of FluentValidationPropertyValidator that can generate client-side rules for PropertyValidator instances of a particular type. This can then be registered with the FluentValidationModelValidatorProvider. If you want to see an example of this, check out the existing implementations of FluentValidationPropertyValidator in FluentValidation.Mvc (eg the RequiredFluentValidationPropertyValidator). This process isn't really ideal as it's somewhat cumbersome....v3 will also add support for MVC 3's IClientValidatable interface which will make this process easier.

Jeremy 

Jun 1, 2011 at 8:24 PM

I got the latest source (v3). The client-side validation for InclusiveBetween is still not working. Is this feature going to come soon? 

-Abhi

Coordinator
Jun 2, 2011 at 6:12 AM

Support for InclusiveBetween is already available in the source for v3. 

Jeremy

Jun 2, 2011 at 2:36 PM

Does the InclusiveBetween client-side validation work for DateTime fields? Thanks

-Abhi

Coordinator
Jun 2, 2011 at 2:39 PM

Client-side InclusiveBetween makes use of the standard jQuery.validate range validator. I've not tried it myself, but if it works with DataAnnotations then it will also work with FluentValidation (FV simply hooks into MVC's client-side validation mechanism and makes use of this, it doesn't use any custom code).

Jul 13, 2011 at 4:41 PM

Hi Jermey,

The client side validation works perfectly for Inclusive between for numeric fields. Can you provide some examples to incorporate client-side validators using IClientValidatable to exisiting property comparison validators like LessThan, LessThanEqualTo  etc. Thanks for the help.

-Abhi