blackriderws
blackriderws

Reputation: 843

Only Accept Numbers with Decimal in a Input Using Javascript?

How to only allow decimals numbers in a Input Ej:

12.00,
12.44,
00.34

Many Thanks

Upvotes: 1

Views: 509

Answers (1)

Oscar Godson
Oscar Godson

Reputation: 32716

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
}

Upvotes: 1

Related Questions