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[
// con esta función comprobás que sea un número
function es_numero(input){
return !isNaN(input)&&parseInt(input)==input;
}
//ahora verificas que sea no sea mayor que 5
function comprobar(){
var laedad = document.getElementById('edad').value;
if(es_numero(laedad)){
if(laedad > 5){
alert("Número mayor que 5\n\rsu número: " + laedad);
document.getElementById('edad').value= 5;
}
} else{
alert("Debe ingresar un número");
}
}
//]]>
El campo debe de tener un valor y este ser menor ó igual a 5
<br /><input type="text" name="edad" id="edad" onblur="comprobar()"/>
Saludos