Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Help with Credit Card Expiry Date Validation

$
0
0
Hi

A call to RuleFor should reference a property directly. You can't call Convert.ToInt32 from within a rule definition.

You'll either need to 1) change the data type of your ExpireMonth and ExpireYear properties to be ints. or 2) Use a custom Must rule that performs the conversion, rather than relying on GreaterThanOrEqualTo.

Example:
// Assuming ExpireYear is still a string
RuleFor(x => x.ExpireYear).Must(x => Convert.ToInt32(x) >= DateTime.Now.Year) 
Basically, you can't mix numeric validators with string properties, so you need to make sure you do the conversion somewhere (either before FV is invoked, or within the validator, but not within the RuleFor)

Viewing all articles
Browse latest Browse all 1917


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>