Web
Article

Flash Script – Form Validation in Flash

By Georgina Laidlaw


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!

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in Front-end, once a week, for free.