I am making a program which checks if the postal code is correct or not. For example, the first character has to be capital, and therefore, the program needs to check that the user input is not lowercase nor is it a numeric value. For the first character of the user input, I tried ensuring that, and if it was, it is supposed to return an invalid statement. This does not work and the program returns an error stating Cannot access a property or method of a null object reference.. I am fairly new at AS3. Please advise. Thanks!
btnDetermine.addEventListener(MouseEvent.CLICK, displayVowels);
function displayVowels(e: MouseEvent): void {
var code: String;
var i: int;
code = String(txtinCode.text);
if (code.substring(0,1) >= 'a' && code.substring(0,1) <= 'z' || code.substring(0,1) is int){
lblPrompt.text = "Invalid. First character is incorrect.";
}
else if (code.substring(1,2) >= 'a' && code.substring(1,2) <= 'z'|| code.substring(1,2) >= 'A' && code.substring(1,2) <= 'Z'){
lblPrompt.text = "Invalid. Second character is incorrect.";
}
else if (code.substring(2,3) >= 'a' && code.substring(2,3) <= 'z'){
lblPrompt.text = "Invalid. Third character is incorrect.";
}
else if (code.substring(3,4) != " "){
lblPrompt.text = "Invalid. Fourth character needs to be a space";
}
else if (code.substring(4,5) >= 'a' && code.substring(4,5) <= 'z'|| code.substring(4,5) >= 'A' && code.substring(4,5) <= 'Z'){
lblPrompt.text = "Invalid. Fifth character is incorrect.";
}
else if (code.substring(5,6) >= 'a' && code.substring(5,6) <= 'z'){
lblPrompt.text = "Invalid. Sixth character is incorrect.";
}
else if (code.substring(6,7) >= 'a' && code.substring(6,7) <= 'z'|| code.substring(6,7) >= 'A' && code.substring(6,7) <= 'Z'){
lblPrompt.text = "Invalid. Eighth character is incorrect.";
}
else{
lblPrompt.text = "Valid postal code!";
}
}
Aucun commentaire:
Enregistrer un commentaire