Make a user input phone number display as (xxx) xxx-xxxx on entry.

Hi Anney
What you need to do is call the function that Carlos shared above in an event handler attached to the element that takes in the phone number.

There are a couple of ways to do this.

  1. If you use a button to accept the number then you implement the button’s onClick handler that gets the value from the phone number element, calls the formatPhoneNumber() function then assigns the result back to the phone number element value property.

  2. You can implement an onChange handler to the phone number element. This will fire when you click outside of the phone number input field. When it fires you can do the same thing as in 1. It depends on the effect you would like.

  3. You can also implement an onKeyChange event handler and process the input value as described in 1. if the key pressed is “Enter”.

Check this out

Steve