0

I want to avoid negative values and decimal values in form input, like 1.25, 4.5 etc using javascript validation.

For negative numbers I am using type="number" and min="0" in input. But how to handle decimal values?

Any help would be great

gofr1
  • 15,066
  • 11
  • 38
  • 47
Deepak Jawalkar
  • 77
  • 2
  • 12

1 Answers1

0

The HTML5 support for the in-form validation might not be available across all browsers.

if(number !== parseInt(number,10)){
  //detects floating point numbers like 1.3  
} else if (number > -1) {
  // detects negative numbers
} 
Amresh Venugopal
  • 8,159
  • 4
  • 33
  • 48