Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript function to format phone number

function formatPhoneNumber(phoneNumberString) {
  var cleaned = ('' + phoneNumberString).replace(/D/g, '')
  var match = cleaned.match(/^(d{3})(d{3})(d{4})$/)
  if (match) {
    return '(' + match[1] + ') ' + match[2] + '-' + match[3]
  }
  return null
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #function #format #phone #number
ADD COMMENT
Topic
Name
2+7 =