1

How to only allow decimals numbers in a Input Ej:

12.00,
12.44,
00.34

Many Thanks

3
  • Do you mean at validation (of some kind) or do you mean not even letting the key presses register in the input? Commented Sep 7, 2011 at 22:32
  • Yes!, I want Validate an input for only set numbers with decimals :), sorry for my bad english Commented Sep 7, 2011 at 22:33
  • You'll want to look into attaching a handler for an onkeydown event. You'll need to check in the event object to see what the actual key pressed was, and then you can either return false or true to allow the event to continue or not. Commented Sep 7, 2011 at 22:44

1 Answer 1

1

Here:

var isFloat = function(n) {
 return n % 1 !== 0;
}

http://jsbin.com/iwitep/edit

So you could do:

if(isFloat(n)){
  //Do something
}
else{
  //Give an error
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.