0

I got an ASPxGridView with some data: enter image description here

When I click on the button to the right, it enters on edit mode.

Here's what I wanna do: I want the edit textbox to allow 3 numbers(with or without decimal places). The decimal places are optional. Eg: it must allow 1.12, 45.1 or 123.

Using masks won't help me and I don't want to use a Regular Expression Validator. I just want the textbox to allow the correct input.

Any ideas?

gabsferreira
  • 3,089
  • 7
  • 37
  • 61
  • What do you want it to do if the input is wrong? Simply reject the offending keystroke that makes it "wrong"? – Ann L. Sep 17 '12 at 16:45
  • Exactly. If the user tries to type a letter or anything that's not a number or a decimal place, I want the textbox to refuse it. – gabsferreira Sep 17 '12 at 16:49
  • 1
    The only way I know how to do that is via Javascript, by capturing the keystrokes typed in that textbox and rejecting the ones you don't want. You can use the `onkeydown` event for that. There is also a jQuery `keypress` event (I believe). – Ann L. Sep 17 '12 at 16:54
  • 1
    You'll still have to validate your input, though: people could type in two decimal points, for example. Your key-rejecting javascript could capture that, too, but it'd need to be more complicated. – Ann L. Sep 17 '12 at 16:55

1 Answers1

1

The only way I know how to do this is via Javascript, by capturing the keystrokes typed in that textbox and rejecting the ones you don't want.

Javascript provides 3 events for that: keydown, keyup, and keypress. jQuery supports these; for keypress, see here. One important section, there:

To determine which character was entered, examine the event object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the .which property so you can reliably use it to retrieve the character code.

You'll still have to do a post-entry validation of your input, though: people could type in two decimal points, for example. Your javascript could try to prevent that, too, but it'd need to be more complicated and would require more effort to test all the relevant cases.

Ann L.
  • 13,760
  • 5
  • 35
  • 66
  • Thank you, I've know created another question, if you can help me on that too http://stackoverflow.com/questions/12464934/validate-caracter-amount-text-length-and-decimal-places-from-input-using-javasc – gabsferreira Sep 17 '12 at 18:21