# HELP! Problem with an empty field and validation

**URL:** <https://forum.kirupa.com/t/help-problem-with-an-empty-field-and-validation/312256>\
**Category:** flash\
**Created:** [July 29, 2010, 8:52am UTC](https://forum.kirupa.com/t/help-problem-with-an-empty-field-and-validation/312256 "2010-07-29T08:52:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![houselight](https://avatars.discourse-cdn.com/v4/letter/h/ec9cab/32.png) [@houselight](https://forum.kirupa.com/u/houselight)\
**Post date:** [July 29, 2010, 8:52am UTC](https://forum.kirupa.com/t/help-problem-with-an-empty-field-and-validation/312256/1 "2010-07-29T08:52:41Z")

</div>

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/](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?
