JAVASCRIPT

Validate US Phone Number Format

Use a JavaScript regular expression to validate various common formats of US phone numbers, including optional dashes, spaces, or parentheses.

const isValidUSPhoneNumber = (phoneNumber) => {
  const regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
  return regex.test(phoneNumber);
};
How it works: This snippet validates common US phone number formats using a regular expression. It allows for flexibility, matching numbers with optional parentheses around the area code, and optional separators like dashes, spaces, or dots between number groups. It ensures the input consists of ten digits arranged in a standard pattern.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs