[thelist] Validating Form for Numeric Data

Chris Marsh chris at webbtech.co.uk
Tue Nov 12 13:40:33 CST 2002


> After a long night last night, I'm a bit lazy today so I was
> hoping for a simple code snippet.
>
> My form has a text input field called "ImpoundNo". What's the
> javascript to ensure that the data entered in that field is
> only numeric (no decimals)?

Something like this may do the trick...

<html>
  <head>
    <title>
      Test
    </title>
    <script>
      function CheckNum(x) {
        if(isNaN(x)) {
          alert("This must be a number");
        }
      }
    </script>
  </head>
  <body>
    <input type='text' onkeyup='CheckNum(this.value);this.focus();return
false;' />
  </body>
</html>

HTH

Regards

Chris Marsh





More information about the thelist mailing list