NumericRangeValidator throws exception when trying to parse an empty string #1592

Closed
opened 2026-01-29 17:55:48 +00:00 by claunia · 3 comments
Owner

Originally created by @BoudewijnPopkema on GitHub (Feb 3, 2025).

Describe the bug
If you bind the NumericRangeValidator to a string object, and the value is set to an empty string, an exception is thrown when calling Validate().

To Reproduce
Steps to reproduce the behavior:

  1. Modify the RadzenBladorDemos: in NumericRangeValidatorConfig.razor, make Quantity a string with a default value of string.Empty
    Image
  2. Open the NumericRangeValidator demo page
  3. Click the "Submit" button
  4. An uncaught exception is thrown, breaking the page

Expected behavior
If required, the validator should show a validation error.
If not required, the validator should pass validation.

Screenshots

Image

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Mozilla Firefox
  • Version: Radzen 5.9.6
Originally created by @BoudewijnPopkema on GitHub (Feb 3, 2025). **Describe the bug** If you bind the NumericRangeValidator to a string object, and the value is set to an empty string, an exception is thrown when calling Validate(). **To Reproduce** Steps to reproduce the behavior: 1. Modify the RadzenBladorDemos: in NumericRangeValidatorConfig.razor, make Quantity a string with a default value of string.Empty ![Image](https://github.com/user-attachments/assets/f9647868-571f-417f-ab76-76cf5085cdb7) 2. Open the NumericRangeValidator demo page 3. Click the "Submit" button 4. An uncaught exception is thrown, breaking the page **Expected behavior** If required, the validator should show a validation error. If not required, the validator should pass validation. **Screenshots** ![Image](https://github.com/user-attachments/assets/5d840612-1c71-4f2d-be3f-230c2cc1727c) **Desktop (please complete the following information):** - OS: Windows 11 - Browser: Mozilla Firefox - Version: Radzen 5.9.6
Author
Owner

@akorchev commented on GitHub (Feb 4, 2025):

The NumericRangeValidator is supposed to work with numeric values - int, float, double, decimal etc. Why do you want to use it with a string?

@akorchev commented on GitHub (Feb 4, 2025): The NumericRangeValidator is supposed to work with numeric values - `int`, `float`, `double`, `decimal` etc. Why do you want to use it with a string?
Author
Owner

@BoudewijnPopkema commented on GitHub (Feb 4, 2025):

I'd agree it's a somewhat questionable design choice, however binding a string value in combination with a numeric value for Min and/or Max does work in all scenarios except for when an empty string value is validated, as the conversion does normally succeed. That to me would imply that it is compatible (the documentation doesn't state which types are compatible explicitly), so I would expect this edge case to have proper exception handling.

From what I can see the fix should be as easy as adding || ex is FormatException to RadzenNumericRangeValidator.cs line 93, I don't mind creating a pull request for it.

@BoudewijnPopkema commented on GitHub (Feb 4, 2025): I'd agree it's a somewhat questionable design choice, however binding a string value in combination with a numeric value for Min and/or Max does work in all scenarios except for when an empty string value is validated, as the conversion does normally succeed. That to me would imply that it is compatible (the documentation doesn't state which types are compatible explicitly), so I would expect this edge case to have proper exception handling. From what I can see the fix should be as easy as adding `|| ex is FormatException` to RadzenNumericRangeValidator.cs line 93, I don't mind creating a pull request for it.
Author
Owner

@akorchev commented on GitHub (Feb 4, 2025):

I don't think we should support this scenario. It has never been intended to work.

@akorchev commented on GitHub (Feb 4, 2025): I don't think we should support this scenario. It has never been intended to work.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1592