attempt_phone can take '' as second argument to refrain from adding an area code...
authorBen Ostrowsky <ben@esilibrary.com>
Thu, 10 Jun 2010 19:47:35 +0000 (19:47 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 16 Jul 2012 15:28:37 +0000 (11:28 -0400)
sql/base/base.sql

index b9703b2..bbe557c 100644 (file)
@@ -705,7 +705,7 @@ CREATE OR REPLACE FUNCTION migration_tools.attempt_phone (TEXT,TEXT) RETURNS TEX
     temp := REGEXP_REPLACE(temp, '^1*[^0-9]*(?=[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(REGEXP_REPLACE(temp, '(.*)?[a-zA-Z].*', E'\\1') , '[^0-9]', '', 'g'));
-    IF n_digits = 7 THEN
+    IF n_digits = 7 AND areacode <> '' THEN
       temp := REGEXP_REPLACE(temp, '[^0-9]*([0-9]{3})[^0-9]*([0-9]{4})', E'\\1-\\2');
       output := (areacode || '-' || temp);
     ELSE
@@ -769,3 +769,10 @@ CREATE OR REPLACE FUNCTION migration_tools.is_staff_profile (INT) RETURNS BOOLEA
   END;
 $$ LANGUAGE PLPGSQL STRICT STABLE;
 
+
+CREATE OR REPLACE FUNCTION migration_tools.is_blank (TEXT) RETURNS BOOLEAN AS $$
+  BEGIN
+    RETURN CASE WHEN $1 = '' THEN TRUE ELSE FALSE END;
+  END;
+$$ LANGUAGE PLPGSQL STRICT STABLE;
+