vallidación de un número entero, ejemplo
Código HTML:
Ver original<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <script type="text/javascript"> //<![CDATA[
function validar(campo){
var elcampo = document.getElementById(campo);
if(!validarEntero(elcampo.value)){
elcampo.value = "";
elcampo.focus();
alert('Debe ingresar un número entero');
}
}
function validarEntero(input){
return (!isNaN(input)&&parseInt(input)==input);
}
//]]>
<input type="text" id="entero" name="entero" value="" onkeyup="validar(this.id);" /> <input type="submit" value="procesar" />
podés cambiar por un evento onsubmit en el form
En caso de querer validar un número, entero o flotante, usas parseFloat en la función validarEntero()
Saludos