- Create new Flash File (File->New or Ctrl + N) and Name it as 'formvalidation'.
- Create form with input fileds .and give Instance name for all text boxes
- Decide the limits for each text box ( for example in this sample first text box will only accept 8 characters)
- Now use the following code
var strlen:String = txt_name.text;
if (strlen.length>8) {
mx.controls.Alert.show("This field only accepts Maximum 8 characters only");
txt_name.text = strlen.substr(0, 8);
}
};
//for validating string length
txt_email.onChanged = function(textfield_txt:TextField) {
var strlen:String = txt_email.text;
if (strlen.length>15) {
mx.controls.Alert.show("This field only accepts Maximum 15 characters only");
txt_email.text = strlen.substr(0, 15);
}
};
//for validating character type
txt_phone.onChanged = function(textfield_txt:TextField) {
if (int(txt_phone.text) == 0) {
mx.controls.Alert.show("This field only accepts Numbers only");
txt_phone.text = "";
}
}; - Now give ctrl+Enter to run the player.
Download Source Code From here