Deepak Jawalkar Deepak Jawalkar - 2 years ago 74
Javascript Question

how to avoid negative,float,and decimal values in form input using javascript validation?

I want to avoid negative values and decimal values in form input, like

etc using javascript validation.

For negative numbers I am using
in input. But how to handle decimal values?

Any help would be great

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download