ecco qui: la funzione restituisce un valore true o false
e devi usarlo nell'evento onsubmit del form in modo che l'invio sia fermato se il campo non è corretto.
Ciaocodice:<html> <head> <title>Documento senza titolo</title> <script> function controlla() { var numero = document.getElementById('id_numero').value; var re = new RegExp("^\\d+\\,\\d{2}$") return numero.match(re); } </script> </head> <body> <form name="form1" method="post" action="paginadati.php" onsubmit="return controlla()"> <input name="id_numero" type="text" id="id_numero" value="189,10" /> <input type="submit" name="Submit" value="Pulsante" /> </form> </body> </html>

Rispondi quotando