phone number refinements

This commit is contained in:
Brian Sweeney 2018-09-06 15:49:39 -06:00
parent 1540b3f8fe
commit 06bb1cd347
2 changed files with 4 additions and 4 deletions

View File

@ -142,8 +142,8 @@ final public class CorrelationAttributeNormalizer {
* Verify it is only numbers and '+'. Strip spaces, dashes, and parentheses. * Verify it is only numbers and '+'. Strip spaces, dashes, and parentheses.
*/ */
private static String normalizePhone(String data) throws CorrelationAttributeNormalizationException { private static String normalizePhone(String data) throws CorrelationAttributeNormalizationException {
String phoneNumber = data.replaceAll("[^0-9\\+]", ""); if(data.matches("\\+?[0-9()\\-\\s]+")){
if(phoneNumber.matches("\\+?[0-9]+")){ String phoneNumber = data.replaceAll("[^0-9\\+]", "");
return phoneNumber; return phoneNumber;
} else { } else {
throw new CorrelationAttributeNormalizationException(String.format("Data was expected to be a valid phone number: %s", data)); throw new CorrelationAttributeNormalizationException(String.format("Data was expected to be a valid phone number: %s", data));

View File

@ -279,13 +279,13 @@ public class CorrelationAttributeNormalizerTest extends NbTestCase {
} }
try { try {
CorrelationAttributeNormalizer.normalize(PHONE_TYPE_ID, badPnEight); CorrelationAttributeNormalizer.normalize(PHONE_TYPE_ID, badPnEight);
//fail("This should have thrown an exception."); //this will eventually pass when we do a better job at this fail("This should have thrown an exception.");
} catch (CorrelationAttributeNormalizationException ex) { } catch (CorrelationAttributeNormalizationException ex) {
assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true); assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true);
} }
try { try {
CorrelationAttributeNormalizer.normalize(PHONE_TYPE_ID, badPnNine); CorrelationAttributeNormalizer.normalize(PHONE_TYPE_ID, badPnNine);
//fail("This should have thrown an exception."); //this will eventually pass when we do a better job at this fail("This should have thrown an exception.");
} catch (CorrelationAttributeNormalizationException ex) { } catch (CorrelationAttributeNormalizationException ex) {
assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true); assertTrue(WE_EXPECT_AN_EXCEPTION_HERE, true);
} }