PostgreSQLdata validation

Validate US Phone Number in PostgreSQL with Regex

Use PostgreSQL regex to validate US phone number formats including area code. SQL examples for NANP phone validation.

The Regex Pattern

Regex pattern

^(\+1)?[\s.-]?\(?[0-9]{3}\)?[\s.-]?[0-9]{3}[\s.-]?[0-9]{4}$

Use this pattern with PostgreSQL's ~ operator.

PostgreSQL SQL Example

-- Validate US format phone numbers in a PostgreSQL contacts table checking for NANP format compliance
SELECT *
FROM your_table
WHERE your_column ~ '^(\\+1)?[\\s.-]?\\(?[0-9]{3}\\)?[\\s.-]?[0-9]{3}[\\s.-]?[0-9]{4}$';

How This Works

Validate US format phone numbers in a PostgreSQL contacts table checking for NANP format compliance. The regex pattern is used with PostgreSQL's ~ operator to filter rows at the database level.

Using regex directly in SQL is efficient for use cases like data validation โ€” it avoids loading data into application memory just to filter it with a regex.

Need a custom SQL + Regex query?

Describe your specific use case in plain English. RegSQL generates the exact PostgreSQL query with the right regex pattern for your schema.

Related SQL Patterns