Only allow number in textfield using javascript

JavaScript function that allow only number in text field

function onlyIntegerNumber(evt){
  var e = evt; // for trans-browser compatibility
  var charCode = e.which || e.keyCode;
  if(charCode == 9){
    return true;
  }
  if((charCode >=35 && charCode <38) || charCode ==39 || e.which ==0){
   alert("Please enter only digit (0-9)");
   return false;
  }
  
  if ((charCode > 31) && (charCode < 48 || charCode > 57) ){
          alert('Please enter only digit (0-9)');
         return false;
   }else{
    return true;
   }
}

function isNumberKey(evt){
    var e = evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;
    
    if(charCode == 46 || charCode == 9){
     return true;
    }
    if((charCode >=35 && charCode <38) || charCode ==39 || e.which ==0){
     alert("Allow only numeric characters (0-9 or .)");
        return false;
    }
    if ((charCode > 31) && (charCode < 48 || charCode > 57) ){
       noty(options);
           return false;
     }else{
    return true;
     }
}

posted under |

0 comments:

Post a Comment

Please provide your valuable comment.

Newer Post Older Post Home

Followers

Powered by Blogger.

Populares

Custom Search