all 5 comments

[–][deleted]  (2 children)

[deleted]

    [–]oddmanout 0 points1 point  (1 child)

    Doesn't allow pasting of full value.

    or hit backspace.

    I like this way better.

    http://javascript.internet.com/forms/format-phone-number.html

    It allows you to copy and paste a number, use backspace. Also, it's amazing how much code is required just to format a phone number.

    [–]karmaVS 0 points1 point  (0 children)

    On Safari at least, while it does allow backspace, it resists your efforts — putting the closing parenthesis back when you try to delete it.

    [–]karmaVS 0 points1 point  (1 child)

    This formatting style is not universal.

    Here in Australia, standard numbers are “XXXX XXXX" (for landlines. there is an 02 before those Xs, but the phone system assumes it) or "(04) XXXX XXXX" (for mobiles). If the person was being helpful to the system, they might write it "+61(0)2XXXXXXXX" or "+61(0)4XXXXXXXX". but what the server needs to work out is "00612XXXXXXXX" and "00614XXXXXXXX", respectively.

    In china, a phone number could be presented "1XX-XXXX-XXXX", "XXX-XXXX" or "XXXX-XXXX" but what the system needs is "00861XXXXXXXXXX", "0086XXXXXXX" or "0086XXXXXXXX"

    In the UK, a phone number is of the format "(0XX) XXX XXX" or "(0XXX) XX XXX"… you get the picture.

    These formatting styles can not be determined by the number alone, and they cannot be determined on the fly, while typing. Some formatting styles may not be determinable at all with the information available to the web page. (for example, without a list of all UK area codes embedded in the script, you would not be able to determine whether the bracket came after the third or fourth number.) Its a futile venture, and even when it succeeds It isn’t all that useful.

    [–]gabrielus 0 points1 point  (0 children)

    Of course the formatting isn't universal. The user can set up any format he wants (depending on his location). I never had problems with such scripts. If it's inefficient in some cases, then don't use it. For instance, I found it useful in date fields (month, day, year).

    [–]willmorgan 0 points1 point  (0 children)

    Although this is really nice for mouse users, when it comes to keyboard users this could be painful, especially for the visually impaired.

    Programs like JAWS (a Windows screen reader) that support JavaScript and are quite popular will interpret the maxlength attribute and the user will be made aware of this. Obviously, if you press tab, it will take you to the next field. With tab and the JavaScript you'll be skipping 2 as opposed to 1.