How do I automatically format phone numbers on user input?

There’s an app for that. You can have form input fields automatically format as phone numbers, so that it’s impossible for a user to enter a syntactically invalid phone number.

From the profile menu top right, select Custom JS (Apps), then install “Real-time phone number formatting (USA)”, one time for your account. All your boxes can now use the feature.

The input field rejects any input not a number, and automatically adds dashes to standardize.

To activate, select the specific phone number field in the Box Editor and at the bottom of the screen enter the metadata key “format_phone_usa”, with value “true”. The field must be of type Text, or be the built-in Phone field.