The if and else statement
Hi,
I am making a program where a user inputs a postal code and then verify if it is valid or not. I made a code to execute it (I used the if/else statement). My code does not have any errors, but once the user enters an invalid postal code, the result is completely wrong. It seems that the result only shows the first label that I assigned, but not the other result. In order to verify the postal code, I needed to make sure that the first, third and sixth characters are capitalized. I did what I needed to do to ensure that, please check my code if there are any changes I should make.
Also, how would I identify if a certain character is a number and if a certain character is a space (no letter)?
I know I have to use str.charAt(str.indexOf("") + 1)
Here is my code:
// This line makes the button, btnCheck wait for a mouse click
// When the button is clicked, the displayCheck function is called
btnCheck.addEventListener(MouseEvent.CLICK, displayCheck);
// This line makes the textinput wait for a mouse click
// When this component is clicked, the clearLabels function is called
txtinCode.addEventListener(MouseEvent.CLICK, clearLabels);
// This is the displayCheck function
// e:MouseEvent is the click event experienced by the button
// void indicates that the function does not return a value
function displayCheck(e:MouseEvent):void
{
// declare variables
var Postal:String;
var Postal2:String;
var Postal3:String;
var str:String;
// get the string from the user
str = txtinCode.text;
// determine if the postal code entered by the user is valid or invalid
Postal = str.charAt(str.indexOf("") + 0);
Postal2 = str.charAt(str.indexOf("") + 2);
Postal3 = str.charAt(str.indexOf("") + 5);
if (Postal.toUpperCase() && Postal2.toUpperCase() + Postal3.toUpperCase())
{
lblDescription1.text = "Valid postal code.";
}
else
{
lblDescription1.text = "Invalid postal code.";
}
}
// This is the clearLabels function
// e:MouseEvent is the click event experienced by the textInput
// void indicates that the function does not return a value
function clearLabels(e:MouseEvent):void
{
lblDescription1.text = "";
txtinCode.text = "";
}
