question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid error message when using ScalePrecisionValidator

See original GitHub issue

System Details

  • FluentValidation version: 8.1.2
  • Web Framework version: .Net Core 2.1

Issue Description

When using the ScalePrecisionValadator to validate the scale and precision of a decimal type property, I am getting this error message when submitting any whole digit number that violates the precision length portion of the validation.

'Decimal Property' may not be more than 9 digits in total, with allowance for 2 decimals. 9 digits and 1 decimals were found.

Shouldn’t the dynamic portion stating, “1 decimals were found.” be 0 decimals found?

i.e ‘123456789’

   RuleFor(x => x.DecimalProperty)
                .SetValidator(new ScalePrecisionValidator(2, 9)).WithName("Decimal Property");

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
robert-mccauslandcommented, Jan 9, 2019

Can’t you use the IgnoreTrailingZeros option on the ScalePrecisionValidator?

var validator = new InlineValidator<Person>();
var scalePrecisionValidator = new ScalePrecisionValidator(2, 9);
scalePrecisionValidator.IgnoreTrailingZeros = true;
validator.RuleFor(x => x.Discount).SetValidator(scalePrecisionValidator);

That should make it ignore any trailing zeros in the value it is validating.

1reaction
JessePlattscommented, Jan 9, 2019

Setting the IgnoreTrailingZeros property to true is fixing this issue. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid error message when using ScalePrecisionValidator
When using the ScalePrecisionValadator to validate the scale and precision of a decimal type property, I am getting this error message when ...
Read more >
Validate only the scale in a decimal value (FluentValidator)
I found the ScalePrecisionValidator but it is validating both. Any method to validate only the scale using the FluentValidator ? c# .net-core ....
Read more >
Built-in Validators — FluentValidation documentation
FluentValidation ships with several built-in validators. The error message for each validator can contain special placeholders that will be filled in when ...
Read more >
Declarative Validation
For each property validator above you can use a Typed Property Validation ... Type Validators can also specify custom Error Codes and Error...
Read more >
Consistent Validation Response for Invalid Value ...
In this case, controller method gets null as input because of invalid type value during the model biding phase. In this case, format...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found