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?