What? Make a mistake entering data? Who me? NO WAY! Right…Every form of data input by a user should be validated in some form or fashion. If you get
clean data in, you won’t get garbage out. This tutorial is going to explain how to validate
numerical data entered into a form using JavaScript.
First, let us begin with
code to insert
JavaScript into your HTML document.
Place these lines between
and tags.This line tells
web browser to expect some JavaScript code and signal
beginning of
the script:
So now
format should look something like this:
My Title
Now on to validating
numerical input.
First we will create a function with one arument:
function validate(mydata){
These lines will test for a blank enty then prompt
user for input:
if (mydata == ""){ alert("Please enter a number.") }
Next we will create a for loop which will look at each character in
data until it