Esempio:
codice:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> <html> <head> <title>test</title> <script type="text/javascript"> function Numeri(){ var imput = document.getElementById("Valore").value if(imput.length>2){ alert("Inserire solo due numeri"); document.getElementById("Valore").value=imput.substring(0,imput.length-1) } else if(imput!="" && !/^([0-9])+$/.test(imput)){ alert('Inserire solo 2 numeri') document.getElementById("Valore").value=''; }} </script> </head> <body> <form id="form1" method="post" action=""> <input name="Valore" id="Valore" type="text" value="" onkeyup="Numeri()" /> </form> </body> </html>![]()

Rispondi quotando