Flash Script – Form Validation in Flash

We teamed up with SiteGround
To bring you up to 65% off web hosting, plus free access to the entire SitePoint Premium library (worth $99). Get SiteGround + SitePoint Premium Now


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!

We teamed up with SiteGround
To bring you up to 65% off web hosting, plus free access to the entire SitePoint Premium library (worth $99). Get SiteGround + SitePoint Premium Now