Ello! Hope you can help me out with this issue. I’m working on a validation function for an inputfield for phonenumbers. And I dont get it.
Basically, what I want is this: user fills in number, and clicks ok (or keypresses enter) and boom, number gets loaded in post.aspx (dont ask). If the phonenumber doesnt start with 06 or has 10 digits, there will be a error announcement.
What I’ve come up with traces the phonenumber when I’ve allready placed it in the movie itself. But when a number is inserted in the movie, it doesnt recognize it and I get the error, allthough it has 10 digits and starts with 06.
My code:
Selection.setFocus("popUp.tel_txtbox");
Selection.setSelection(2,2);
yournumber = popUp.tel_txtbox.text;
var startingCharacters:String = "06";
var reqLength:Number = 10;
popUp.mcAnswer.onRelease = function() {
function stripNumber(input:String):String {
var output:String = new String();
for (i=0; i<input.length; i++) {
if (!isNaN(Number(input.charAt(i)))) {
output += input.charAt(i);
}
}
if ((output.indexOf(startingCharacters, 0) != 0) || (output.length != reqLength)) {
//Whatever you want it to do when the number doesn't meet the criteria
throw new Error("This doesnt work");
} else {
return output;
}
}
trace(stripNumber(yournumber));
}
Anyone that can help me out with this?