0

My case is that I have a textbox for Age input. I use RegularExpressionValidator control to validate the input, like this:

<asp:RegularExpressionValidator ... ValidationExpression="\s*\d+\s*" ... />

The validation accepts digit inputs which maybe include whitespaces on the beginning or at the end of numbers. So if one user types " 32 " into the textbox, the input is legal. But afterwards I want the text box shows the better form, "32" - throw away all whitespaces.

I know it is possible to process by javascript, however is there a shorter way? or another more powerful validator control?

Khanh Vu
  • 53
  • 7
  • I'm not sure exactly why you would allow them to enter spaces. Why not just use a RangeValadator or a CompareValidator (to type int)? – CoderMarkus Aug 20 '12 at 03:34
  • @TrueDevelopment: Thanks for your suggest. I just dont want users have to input again if they only type one redundant space while the validator is stil able to filter numbers. – Khanh Vu Aug 20 '12 at 04:03
  • 1
    The only client side solution I could think of is using JS. Otherwise, if a PostBack is involved, just `Trim()` the value. – CoderMarkus Aug 20 '12 at 04:05

0 Answers0