Skip to content

bigfunctions > is_phone_number_valid

is_phone_number_valid

Signature

is_phone_number_valid(phone_number, options)

Description

Return if phone_number is valid using libphonenumber-js library.

Argument options can be null or must be a json with the following keys: defaultCountry, defaultCallingCode and extract as described in the library documentation.

Examples

1. Check an international phone_number (starting with +)

select bigfunctions.eu.is_phone_number_valid('+33123456789', null)
select bigfunctions.us.is_phone_number_valid('+33123456789', null)
select bigfunctions.europe_west1.is_phone_number_valid('+33123456789', null)
+----------+
| is_valid |
+----------+
| true     |
+----------+

2. Check a national phone_number

select bigfunctions.eu.is_phone_number_valid('0123456789', json '{"defaultCountry": "FR"}')
select bigfunctions.us.is_phone_number_valid('0123456789', json '{"defaultCountry": "FR"}')
select bigfunctions.europe_west1.is_phone_number_valid('0123456789', json '{"defaultCountry": "FR"}')
+----------+
| is_valid |
+----------+
| true     |
+----------+

3. If no phone number is found in phone_number, it returns false

select bigfunctions.eu.is_phone_number_valid('Hello!', null)
select bigfunctions.us.is_phone_number_valid('Hello!', null)
select bigfunctions.europe_west1.is_phone_number_valid('Hello!', null)
+----------+
| is_valid |
+----------+
| false    |
+----------+

4. By default, if the given phone_number text contains a valid phone number among other text, it returns true.

select bigfunctions.eu.is_phone_number_valid('Hello +33123456789 !', null)
select bigfunctions.us.is_phone_number_valid('Hello +33123456789 !', null)
select bigfunctions.europe_west1.is_phone_number_valid('Hello +33123456789 !', null)
+----------+
| is_valid |
+----------+
| true     |
+----------+

5. To consider that phone_number cannot have additional text use extract: false as option

select bigfunctions.eu.is_phone_number_valid('Hello +33123456789 !', json '{"extract": false}')
select bigfunctions.us.is_phone_number_valid('Hello +33123456789 !', json '{"extract": false}')
select bigfunctions.europe_west1.is_phone_number_valid('Hello +33123456789 !', json '{"extract": false}')
+----------+
| is_valid |
+----------+
| false    |
+----------+