Tag Archives: phone number

Format Phone #

Actionscript:
  1. var phoneField:TextField = new TextField();
  2. with (phoneField) {
  3.     type=TextFieldType.INPUT;
  4.     maxChars=12;
  5.     restrict="0-9";
  6.     border=true;
  7.     width=100;
  8.     height=20;
  9.     x=y=20;
  10. }
  11. addChild(phoneField);
  12.  
  13. phoneField.addEventListener(TextEvent.TEXT_INPUT, onInput);
  14.  
  15. function onInput(evt:TextEvent):void {
  16.     if (phoneField.length==3 || phoneField.length==7) {
  17.         phoneField.appendText("-");
  18.         var leng:int=phoneField.text.length;
  19.         phoneField.setSelection(leng, leng);
  20.     }
  21. }

Quick way to make sure text input is formatted like a phone number.

Posted in string manipulation | Also tagged , | Leave a comment