Motive : I have a decimal property in a class which I wish to validate so that it adheres to regex “^\d{1,7}.\d{2,7}$”
So i have applied the Regex validator attribute to the property
[RegexValidator(@"^\d{1,7}\.\d{2,7}$"...)]
public Decimal MyDecimalProperty { get; set; }
Then, via propertyproxyvalidator on my asp.net page i have tied a textbox validation to this property type.
<cc1:PropertyProxyValidator ID="MyValidator" runat="server" ControlToValidate="MyTextBox"
PropertyName="MyDecimalProperty" SourceTypeName="Myclass, Mydll"></cc1:PropertyProxyValidator>
At runtime i get this error when validation gets performed:
“Value to validate is not of the
expected type: expected System.String
but got System.Decimal instead.”
Any idea how to get around this issue, or an alternate to achieve my motive ?
Regular expressions are built to work on strings, not numeric types. Perhaps you need something like this instead:
Also, update the
PropertyNameattribute of thePropertyProxyValidator.