dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Help! Trouble with an empty field and verification

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    2

    Help! Trouble with an empty field and verification

    New to the forums. Thanks for your help.

    I have a script to verify a zip code. It works fine except when the field is empty.

    This is the script:

    submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
    function ValidateAndSend(event:MouseEvent):void{

    if (validateZipCode(zip_txt.text) == false) {

    zip_txt.textColor = 0xFF0000;

    } else {

    var targetURL:URLRequest = new URLRequest("https://www.blahblahblah.com/"+(zip_txt.text));
    navigateToURL(targetURL);
    }

    }
    function validateZipCode(zipString:String):Boolean {

    var myRegEx:RegExp= /^([0-9]{5}(?:-[0-9]{4})?)*$/;
    var myResult:Object = myRegEx.exec(zipString);
    if(myResult == null) {
    return false;
    }
    return true;

    }

    If I enter too few numbers it works and turns the text red. If I enter the correct numbers it works and sends me to the site. But if I leave the field blank and click, it sends me to the site anyway.

    Any thoughts?

    Thnaks

  2. #2
    FK Romeo martiansam's Avatar
    Join Date
    Oct 2001
    Location
    Bombay, India
    Posts
    223

    Check for condition

    function validateZipCode(zipString:String):Boolean {

    var myRegEx:RegExp= /^([0-9]{5}(?:-[0-9]{4})?)*$/;
    var myResult:Object = myRegEx.exec(zipString);

    if(myResult == null || zipString == "" || zipString == " ") {
    return false;
    }
    return true;

    }
    sameer rao

    there...you see!!

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    2

    Thanks

    That did it. I tried many similar things. it was "zipString == " "" that did it.

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