Forum Discussion
How to validate phone numbers?
- 1 year ago
Hey James__ ,
Since you're using Power BI Desktop and SQL, here are solutions for both:
Power BI (Power Query): You can clean and validate phone numbers using Power Query steps:
Remove non-numeric characters:
Text.Select([PHONE1], {"0".."9"})Create a custom column to validate:
let CleanPhone = Text.Select([PHONE1], {"0".."9"}) in if Text.Length(CleanPhone) = 11 and Text.StartsWith(CleanPhone, "07") and CleanPhone <> "00000000000" then "Valid" else "Invalid"Repeat for PHONE2 and PHONE3, then create a final column like:
if [PHONE1_Valid] = "Valid" or [PHONE2_Valid] = "Valid" or [PHONE3_Valid] = "Valid" then "Valid Customer" else "Invalid Customer"
SQL Approach:
SELECT *, CASE WHEN (LEN(PHONE1) = 11 AND PHONE1 LIKE '07%' AND PHONE1 NOT IN ('00000000000', '12345678901')) OR (LEN(PHONE2) = 11 AND PHONE2 LIKE '07%' AND PHONE2 NOT IN ('00000000000', '12345678901')) OR (LEN(PHONE3) = 11 AND PHONE3 LIKE '07%' AND PHONE3 NOT IN ('00000000000', '12345678901')) THEN 'Valid' ELSE 'Invalid' END AS PhoneNumberStatus FROM YourTable;If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam
Hey James__ ,
Since you're working with UK-based phone numbers, a common format to expect is exactly 11 digits, typically starting with 07 for mobile numbers. To identify customers with invalid phone numbers across PHONE1, PHONE2, and PHONE3, you can follow these steps:
Clean the Data: Remove any spaces, dashes, or non-numeric characters from each phone number field.
Check for Proper Length: Only keep numbers that are exactly 11 digits long.
Filter Out Obvious Invalid Entries: Watch for patterns like "00000000000", "12345678901", or repeated characters.
Validate Format (Optional): If you're checking mobile numbers specifically, you can use a pattern like 07XXXXXXXXX (where X = digit).
If you're using tools like Excel, Power BI, SQL, or Python, let me know I’d be happy to help with a more specific approach. Also, when evaluating a customer, consider them valid if at least one of the three phone fields contains a genuine number.
For Detailed Information:
How to Clean and Validate Phone Numbers in Excel – ExcelJet
Validate Phone Numbers in Power BI using Power Query – RADACAD
SQL Query to Validate Phone Numbers – Stack Overflow Thread
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam