views:

91

answers:

4

for example, I want the textfield input number only. my idea is when the user typing, it will call a javascript to check whether it is valid, if it is not valid, I delete the text which is just entered. But I think it is very complex to do so. Is there any simple way to do so?

+1  A: 

Put a validation on submit.

rahul
A: 

The script to do this is here. It's a pretty common requirement.

http://javascript.internet.com/forms/validate-numeric-only.html

David Stratton
it have a bug... try to hold down the key.... it still can display the letter.
Ted Wong
A: 

JQuery Masking could be a good choice: http://digitalbush.com/projects/masked-input-plugin/

o.k.w
A: 

I think, like o.k.w said, jQuery Masking would be a good choice because of 2 things:

  1. jQuery is solid and fast

  2. Masking is more user friendly than just deleting user input on the fly without any notification. Masking gives them a graphical reference of what type of input is expected and what the input might look like.

MysticEarth