»
EnglishFrenchVietnamese

Print - Phone number formatter - JavaScriptBank.com

Full version: jsB@nk » Calculation » Phone number formatter
URL: https://www.javascriptbank.com/phone-number-formatter.html

Phone number formatter © JavaScriptBank.comFormats phone number to the standard (xxx)xxx-xxxx format. This JavaScript will first eliminate all non-numeral values and check to see whether the value is a valid 10 digit long phone number. If it is, the number is formatted with the parenthesis and the dash and returns the value to the phone number textbox. If less than 10 numbers, a blank value is returned and an error message shows up.

Full version: jsB@nk » Calculation » Phone number formatter
URL: https://www.javascriptbank.com/phone-number-formatter.html



JavaScript
<SCRIPT language=javascript>function phoneFormat(obj){newValue = obj.value.replace(/\D/g,'');if (newValue.length < 10 || newValue.length > 10){newValue = '';alert('Please enter a valid phone number.');}if (newValue != '' && newValue.length == 10){newValue = "(" + newValue.substring(0,3) + ")" + newValue.substring(3,6) + "-" +    newValue.substring(6,10);}return newValue;}</SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<INPUT type=button value="Phone Number" name="Phone Number"> <INPUT id=txtPhone onblur=this.value=phoneFormat(this) maxLength=13 size=13 name=txtPhone><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->