From 5e26cba425a8162ecb54bce5ca2f5d55a61f3655 Mon Sep 17 00:00:00 2001 From: Ben Ostrowsky Date: Mon, 12 Apr 2010 22:06:41 +0000 Subject: [PATCH 1/1] Handling a few more exceptions... --- sql/base/base.sql | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/base/base.sql b/sql/base/base.sql index 5137ef2..ded01ba 100644 --- a/sql/base/base.sql +++ b/sql/base/base.sql @@ -701,9 +701,10 @@ CREATE OR REPLACE FUNCTION migration_tools.attempt_phone (TEXT,TEXT) RETURNS TEX output TEXT := ''; n_digits INTEGER := 0; BEGIN - temp := REGEXP_REPLACE(phone, '^1[^0-9]*', ''); + temp := phone; + temp := REGEXP_REPLACE(temp, '^1*[^0-9]*', ''); temp := REGEXP_REPLACE(temp, '[^0-9]*([0-9]{3})[^0-9]*([0-9]{3})[^0-9]*([0-9]{4})', E'\\1-\\2-\\3'); - n_digits := LENGTH(REGEXP_REPLACE(temp, '[^0-9]', '', 'g')); + n_digits := LENGTH(REGEXP_REPLACE(REGEXP_REPLACE(temp, '(.*)?[a-zA-Z].*', E'\\1') , '[^0-9]', '', 'g')); IF n_digits = 7 THEN temp := REGEXP_REPLACE(temp, '[^0-9]*([0-9]{3})[^0-9]*([0-9]{4})', E'\\1-\\2'); output := (areacode || '-' || temp); -- 1.7.2.5