Answers for "js valid canada phone number"

9

js regex validate phone number

My regex of choice is:

/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im
Valid formats:

(123) 456-7890
(123)456-7890
123-456-7890
123.456.7890
1234567890
+31636363634
075-63546725
Posted by: Guest on February-07-2020
3

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
}
Posted by: Guest on November-13-2020

Code answers related to "js valid canada phone number"

Code answers related to "Javascript"

Browse Popular Code Answers by Language