Need to convert a regex validation pattern used to validate phone numbers into a SELECT query in SQL to validate a list of phone numbers in a SQL table
Regex = ^\s*1?[ \-\(\.\/]*[2-9]\d{2}[ \-\.\(\)\/]*[2-9]\d{2}[ \-\.\(\)\/]*\d{4}\s*$|^\s*011[ \-]*[2-9][ \-\(\.\/\)\,\d]
I have tried the PATINDEX function to pass the above expression. Below is my query
DROP TABLE #PhoneNumberList
SELECT * INTO #PhoneNumberList
FROM (
SELECT '8049901000' AS PhoneNumber, 'Valid' as ValidationResultNeeded
UNION
SELECT '800-200-1000', 'Valid'
UNION
SELECT '1000900000' , 'Invalid'
UNION
SELECT '4053366463' , 'Valid'
UNION
SELECT '(405)334-5665' , 'Valid'
UNION
SELECT '405334(6463)' , 'Invalid'
union
SELECT '7341234321' , 'Invalid'
UNION
SELECT '3961573999' , 'Invalid'
UNION
SELECT '40533406463' , 'Invalid'
)A
SELECT * , Patindex('^\s*1?[ \-\(\.\/]*[2-9]\d{2}[ \-\.\(\)\/]*[2-9]\d{2}[ \-\.\(\)\/]*\d{4}\s*$|^\s*011[ \-]*[2-9][ \-\(\.\/\)\,\d]+$',PhoneNumber) AS RegExValidation
FROM #PhoneNumberList
order by 2
Im getting a value of zero for all phone numbers. I was expecting to get a value other than 0 for invalid phone numbers. Am I using this function correctly to get the right validation? Or is there another way to write this SQL statment?