A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Forms validation or check up issues

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    34

    Forms validation or check up issues

    Hi Guys,

    I am doing some forms in Flash Cs4 with AS3. The forms are working well, but i have a code to check if people have enter information in every field. But the verification only works for 2 field. The code is exactly the same for the other but it doesn't work. Can you double check my code and maybe explain me why it doesn't work or maybe how to replace the validation code by another.

    The validation works only for the LastName data and Email field.

    Here's the code;

    submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);

    function ValidateAndSend(event:MouseEvent):void{

    //validate form fields
    if(!txtContactFirstName.length) {
    status_txt.text = "*Please enter your first name.";
    } else if(!txtContactEmail.length) {
    status_txt.text = "*Please enter an email address";
    } else if(!validateEmail(txtContactEmail.text)) {
    status_txt.text = "*Please enter a VALID email address";
    } else if(!txtAccountCity.length) {
    status_txt.text = "*Please enter a city.";
    } else if(!txtContactLastName.length) {
    status_txt.text = "*Please enter your last name";
    } else {

    status_txt.text = "Thanks " + txtContactFirstName.text + "your information has been sent!";

    Thanks guys

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    I would more strictly define your conditions. Try checking against a string representation of each valid entry rather then this '!' boolean operator. So instead of ,

    Code:
     if(!txtContactFirstName.length)
    try

    Code:
    if(txtContactFirstName.text == "")
    so on and so on.

    Also , this isn't a very robust validation method. Basically , as long as a user types in at least 1 character into each field it will validate and send. Thats not good. You should really be checking to see what specifically they are entering. Make sure they cant enter html tags , or scripts or something weird into these fields. And you surely do not have to reinvent the wheel here. Im confident , a few minutes of google searching form validation procedures will return you some great code , that you can port over into your application.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center