A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: form field to check length of input text

  1. #1
    Member
    Join Date
    Feb 2005
    Location
    manchester, england
    Posts
    98

    form field to check length of input text

    i'm trying to get a Flash form to test certain conditions, one of which is the full date (ie 2006 as opposed to 06), but the AS below (in bold) isn't working... does anybody know the right script?


    on (release) {
    if (!name.length) {
    text.emailstatus = "please enter your name";
    } else if (!email.length || email.indexOf("@") == -1 || email.indexOf(".") == -1) {
    text.emailstatus = "please enter a valid email";
    } else if (!message.length) {
    text.emailstatus = "please enter your message";
    } else if (!year.length < 4) {
    text.emailstatus = "please enter the full year";

    } else {
    loadVariablesNum("MailPHP.php", "0", "POST");
    text.emailstatus = "message sent - thankyou";
    }
    }

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    i think you're trying to say "if year is less than 4 chars long give error"
    which you could do like you are, but you need to change the order its evaulated, usually accomplished by parenthesising - just like in normal math

    so instead of !year<4 use !(year<4)

    but you want it to be exactly 4 long, so the best bet would be to say year!=4

  3. #3
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    try
    Code:
    }else if (year.length != 4){

  4. #4
    Member
    Join Date
    Feb 2005
    Location
    manchester, england
    Posts
    98
    thanks very much! works perfectly

  5. #5
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    i'm using the same script and advice (Actionscript 2), as below, but now this isn't working.....

    Code:
    	if (name.length != 5) {
    		nametitle.text = "enter your full name";
    I don't want the number of characters in the name to be less than 5.

    can somebody please tell me why it keeps telling me to "enter your full name" when i have far more than 5 characters entered?

    thanks

  6. #6
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    is there anyone who can please help me with this?

  7. #7
    Member
    Join Date
    Mar 2009
    Location
    Brooklyn, NY
    Posts
    77
    You just need it to say:
    Code:
    if (name.length < 5)
    What you have now will tell you to enter your full name unless the name is exactly 5 letters long
    Break it until it works.

  8. #8
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    thanks for the reply cessnajumpin, but it doesn't work. wondering if there is some conflict somewhere. here is the full code for the button...


    on (release) {
    if (name.length<5) {
    nametitle.text = "please enter your full name";
    } else if (!email.length || email.indexOf("@") == -1 || email.indexOf(".") == -1) {
    emailtitle.text = "please enter a valid email";
    } else {
    loadVariablesNum("NewsletterPHP.php", "0", "POST");
    mcNavNewsletter.gotoAndPlay('fade');
    btnews.enabled = false;
    mcResponse.gotoAndPlay(2);
    }
    }
    on (rollOver) {
    mcNavNewsletter.gotoAndPlay('over');
    }
    on (rollOut) {
    if (mcNavNewsletter._currentframe>1) {
    mcNavNewsletter.gotoAndPlay('out');
    }
    }



    (the email code works fine)

  9. #9
    Member
    Join Date
    Mar 2009
    Location
    Brooklyn, NY
    Posts
    77
    What part isn't working? Just the name? Is it still giving you the "please enter..." or something else?
    Break it until it works.

  10. #10
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    ideally i'd like someone to enter their name so that the default "name" isn't accepted (thus the reason for more than 5 letters), and also that people enter longer full names etc.

    at the moment it's only the email address part that works ok.

    please take a look... http://www.fkda.co.uk then select "practice" then "news"

    (don't worry about sending test name/email... will just delete afterwards)

  11. #11
    Member
    Join Date
    Mar 2009
    Location
    Brooklyn, NY
    Posts
    77
    That's weird..it could be something with using the variable "name".
    What happens when you use this for the validation:
    Code:
    if (nametitle.length < 5) {
    Break it until it works.

  12. #12
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    good idea... changed the variable to "fullname" but still not working. code now is.......

    Code:
    on (release) {
    	if (fullname.length<5) {
    		nametitle.text = "please enter your full name";
    	} else if (!email.length || email.indexOf("@") == -1 || email.indexOf(".") == -1) {
    		emailtitle.text = "please enter a valid email";
    	} else {
    		loadVariablesNum("NewsletterPHP.php", "0", "POST");
    		mcNavNewsletter.gotoAndPlay('fade');
    		btnews.enabled = false;
    		mcResponse.gotoAndPlay(2);
    	}
    }
    on (rollOver) {
    	mcNavNewsletter.gotoAndPlay('over');
    }
    on (rollOut) {
    	if (mcNavNewsletter._currentframe>1) {
    		mcNavNewsletter.gotoAndPlay('out');
    	}
    }

  13. #13
    Member
    Join Date
    Mar 2009
    Location
    Brooklyn, NY
    Posts
    77
    Ok, try using the text field itself as the validation. What happens when you try:
    Code:
    if (nametitle.length < 5) {
    Break it until it works.

  14. #14
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    that doesn't work either :-(

  15. #15
    Member
    Join Date
    Mar 2009
    Location
    Brooklyn, NY
    Posts
    77
    can you post your file?
    Break it until it works.

  16. #16
    Member
    Join Date
    Oct 2004
    Location
    manchester, england
    Posts
    55
    will try to strip the fairly large file down to just this section (news page) over the weekend.

    incidentally i added an exclamation in front of the variable (as below), and it then prompted for "full name", but this then wouldn't disappear no matter how many characters i entered.

    PHP Code:
        if (!fullname<5) { 

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