JavaScript Number Validation From 0 - 10 -


i need check if number between 0 , 10 in javascript.

the code:

<html> <head> <script> function compruebacampo(evt,campotexto) {     //validar la existencia del objeto event     evt = (evt) ? evt : event;      //extraer el codigo del caracter de uno de los diferentes grupos de codigos     var charcode = (evt.charcode) ? evt.charcode : ((evt.keycode) ? evt.keycode :             ((evt.which) ? evt.which : 0));      //predefinir como valido     var respuesta = true;      //validar si el codigo corresponde     if (charcode > 31 && (charcode < 48 || charcode > 57)) {         //asignar false la respuesta si es de los no aceptables         respuesta = false;     }      //valida rango valido 1-10     if ((campotexto.value + string.fromcharcode(charcode))>10 ||(campotexto.value +             string.fromcharcode(charcode))<0) {         respuesta = false;     }      //regresar la respuesta     return respuesta; } </script>  </head> <body>     <input type="textbox" onkeypress="return compruebacampo(event,this)" > </body> </html> 

i have it's valid 1-10. how can include '0' once in number validation?

function compruebacampo(evt, campotexto) {     var charcodeofzero = 48;     var numberjustentered = evt.charcode - charcodeofzero;     var fullstring = campotexto.value + "" + numberjustentered;      var matchesone = false;     (var = 0; <= 10; i++) {         if (fullstring == ("" + i))               matchesone = true;     }      if (!matchesone) return false; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -