Reputation: 1138
I have a textbox for entering a currency amount, with a RangeValidator control making sure the value entered is between 1 and 99999999.99.
The field also has an “onblur” event that fires off some JavaScript to format the input with commas and a decimal point (e.g. 12455 -> 12,455.00). There's also a "onfocus" event that reverses the "onblur" effect, putting the value back into an editable format (e.g. 12,455.00 -> 12455.00.
My problem is the RangeValidator doesn't like the formatted value with the commas and subsequently fails on the validation.
Is there a way to get around that? I want to be able to range check the value, yet still present it formatted when the textbox doesn't have focus. I realize that a CustomValidator could probably work, but I was hoping to get this to work with the RangeValidator.
Upvotes: 1
Views: 1658
Reputation: 343
Just change the RangeValidator's Type to currency (Type="Currency") and it will accept commas and any other currency symbols.
Upvotes: 2
Reputation: 964
Simple. Instead of Using the Range validator (a sever side control for client side validation), add few lines of code in the OnBlur method of the Javascript which would be better.
or
Use something like below link
Upvotes: 0