I am working with JSF 2 and I want to validate an inputText with javascript, in my script is defined that only numbers can be entered but the letters are also entered
my code
jsf
<p:inputText id="idDNI" style="width:140px;" value="#{empleadoBean.emVista.strDNI}" maxlength="8" required="true" onkeypress ="validar(event)"/>
js
function validar(e) {
  var unicode=e.keyCode? e.keyCode : e.charCode;
  if (unicode == 8 || unicode == 46 || unicode == 37 || unicode == 39) {
       return true;
  }
  else if ( unicode < 48 || unicode > 57 ) {
       return false;
  }
  else{
      return true;
  } 
}
Thanks for all, excuse me for my English
 
     
    