Actionscript:
-
var phoneField:TextField = new TextField();
-
with (phoneField) {
-
type=TextFieldType.INPUT;
-
maxChars=12;
-
restrict="0-9";
-
border=true;
-
width=100;
-
height=20;
-
x=y=20;
-
}
-
addChild(phoneField);
-
-
phoneField.addEventListener(TextEvent.TEXT_INPUT, onInput);
-
-
function onInput(evt:TextEvent):void {
-
if (phoneField.length==3 || phoneField.length==7) {
-
phoneField.appendText("-");
-
var leng:int=phoneField.text.length;
-
phoneField.setSelection(leng, leng);
-
}
-
}
Quick way to make sure text input is formatted like a phone number.