16 may 2011

JavaScript Validar Input acepta Flotantes de 2 decimales

function isNumberKey(evt)
{
 var e = evt; // for trans-browser compatibility
  var charCode = e.which || e.keyCode;
 var patt1=/^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
 var str = document.Fevaluaciones.propObj.value+String.fromCharCode(charCode);
 //alert(patt1.exec(str));
 if(patt1.test(str)) {
  try {
   part= str.split(".");
   if(part[1].length <= 2)
    return true
   else 
    return false;
  } catch(e){
   return true;
  }
 } else {
  return false
 };
}

No hay comentarios.: