A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: JavaScript form validation

  1. #1
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929

    JavaScript form validation

    I've got a form that I want to test to make sure the user entered a zip code in a valid array and I'm not sure how to check it...

    The zip code list is like 11111, 11114, 11117, so I can't just include a range...

    I had written a function like:

    Code:
    function validate_zip(field,alerttxt)
    {
    	with (field)
    	{
    		if (value==null||(value<"11111"||value>"11174"))
    		  {alert(alerttxt);return false;}
    		else {return true}
    	}
    }
    but, I have to exclude the non-inclusive zip codes...so, how do I create an array and test against it???

    TIA!!!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I just wrote this basic function you can use to find a value in an array.
    PHP Code:
    <script type="text/javascript">
    var 
    zipArray = new Array("11111","11112","11113","11114");

    function 
    inArray(v,a)
    {
        for(
    0a.lengthi++)
        {
            if(
    == a[i])
            {
                return 
    true;
            }
        }
        return 
    false;
    }

    // Usage
    alert(inArray('11114',zipArray));// returns true
    alert(inArray('11115',zipArray));// returns false
    </script

  3. #3
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929
    SWEET!!! That did it!!

    Thanks!!
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

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