If you create a form for your site, you should, of course, check for errors in user input before the form can be successsfully submitted.

This simple tutorial will show you how to check whether a user-entered number is actually a number, not some other character. Download the sample files here.

1. Create an empty text box, and give it the variable name "txt".

2. Create a button of your choice, right click the button, and select "actions". Insert this action:

on (release) 
{
if(int(txt)==0)
{
txt="Not Number";
}
else
{
txt="Is Number";
}
}

3. That’s it! Now, take it for a spin! Enter a letter or number into your form, and see it function.

Here’s how it works. If any letter appears in text box, int() returns 0, otherwise, int returns the entered number. Simple!

Georgina has more than fifteen years' experience writing and editing for web, print and voice. With a background in marketing and a passion for words, the time Georgina spent with companies like Sausage Software and sitepoint.com cemented her lasting interest in the media, persuasion, and communications culture.

No Reader comments

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.