|
|
|
Benefits Of Making Your Website Accessible To Disabled Users – Part 2: The Business Case
The Disability Discrimination Act states that service providers must not discriminate against disabled people. A website is regarded as a service and therefore comes under this law. Some organisations are changing to their websites, but many are...
Beware of Fake SEO consultants.
Some important facts you need to know before you choose your Search engine optimization company or an SEO specialist . =>If a Search engine optimization firm has guaranteed you number 1 position on Google, number 1 Yahoo listing , Top Msn ranking...
Get Better Search Engine Rankings with RSS
RSS is the latest craze in online publishing. But what exactly is RSS? RSS or Rich Site Syndication is a file format similar to XML, and is used by publishers to make their content available to others in a format that can be universally...
New Customizable JavaScript Menu for Web Applications
Minsk, Belarus, October 11, 2005 -- Software development company Scand released its new product - dhtmlxMenu v1.0 .
This JavaScript menu enables web developers to design and edit a simple DHTML menu in a very convenient way.
dhtmlxMenu has...
Two Easy Methods To Optimize Your JavaScript
Two Easy Methods To Optimize Your JavaScript
by Steve Shaw
Many web sites, even those owned by people we all think of as gurus in the Internet marketing business, have large blocks of JavaScript at the top of their web pages, sometimes...
|
|
| |
|
|
|
|
Validating Numerical Input with JavaScript
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 the code to insert the JavaScript into your HTML document.
Place these lines between the and tags.
This line tells the web browser to expect some JavaScript code and signal the beginning of
the script:
So now the format should look something like this:
My Title
Now on to validating the numerical input.
First we will create a function with one arument:
function validate(mydata){
These lines will test for a blank enty then prompt the user for input:
if (mydata == ""){ alert("Please enter a number.") }
Next we will create a for loop which will look at each character in the data until it
reaches the end:
for(var i=0;i < mydata.length;i++){
Now create a variable and assign the counter variable value to it:
var mydigit = mydata.charAt(i)
To screen out symbols, punctuation, and letters, place an if statement in the loop:
if(mydigit < "0" || mydigit > "9"){
The || in the if statement scans for both conditions.
The next line will alert the user to any mistakes he/she has made:
alert(mydigit + " is not a number.")
Here is the complete code including HTML: ============================================= Numerical Validation
| | | | | | |