I'm trying to use RegEx to validate phone numbers saved in a SQL Server 2016 Table. In this table there are thousands of fax numbers which stored as different formats. Ex : 800-123-4567
, 800/123-4567
, 800#123/4567
etc. Now I'm wanting to use RegEx to validate the phone numbers also output them in a way without any special characters or spaces in between. Ex : 8001234567
.
Here's what I have tried which does not seems to work for some reason. If anyone out there could correct me what I'm doing wrong here, I would really appreciate it.
DECLARE @expres VARCHAR(50) = '%[/,-,\,#]%'
DECLARE @cmpfax as CHAR(100);
SELECT @cmpfax = cmp_fax FROM cicmpy WHERE LTRIM(RTRIM(cmp_code)) = '100373' AND cmp_fax IS NOT NULL;
SELECT REPLACE(@cmpfax, @expres, '#');
Here's my dbfiddle for the above code which I've tested.