[BAEL-3944] Real like phone numbers

This commit is contained in:
sergio41 2020-04-24 13:07:05 +02:00
parent 5bb2977eb0
commit 953b8d4640
1 changed files with 6 additions and 6 deletions

View File

@ -12,28 +12,28 @@ public class PhoneNumbersRegexUnitTest {
@Test
public void whenMatchesTenDigitsNumber_thenCorrect() {
Pattern pattern = Pattern.compile("^\\d{10}$");
Matcher matcher = pattern.matcher("1234567890");
Matcher matcher = pattern.matcher("2055550125");
assertTrue(matcher.matches());
}
@Test
public void whenMatchesTenDigitsNumberWhitespacesHyphen_thenCorrect() {
Pattern pattern = Pattern.compile("^(\\d{3}[- ]?){2}\\d{4}$");
Matcher matcher = pattern.matcher("123 456 7890");
Matcher matcher = pattern.matcher("202 555 0125");
assertTrue(matcher.matches());
}
@Test
public void whenMatchesTenDigitsNumberParenthesis_thenCorrect() {
Pattern pattern = Pattern.compile("^\\(?\\d{3}\\)?[- ]?\\d{3}[- ]?\\d{4}$");
Matcher matcher = pattern.matcher("(123)-456-7890");
Matcher matcher = pattern.matcher("(202)-555-0125");
assertTrue(matcher.matches());
}
@Test
public void whenMatchesTenDigitsNumberPrefix_thenCorrect() {
Pattern pattern = Pattern.compile("^(\\+\\d{1,3}( )?)?\\(?\\d{3}\\)?[- ]?\\d{3}[- ]?\\d{4}$");
Matcher matcher = pattern.matcher("+111 (123)-456-7890");
Matcher matcher = pattern.matcher("+111 (202)-555-0125");
assertTrue(matcher.matches());
}
@ -43,8 +43,8 @@ public class PhoneNumbersRegexUnitTest {
"|^(\\+\\d{1,3}( )?)?(\\d{3}[ ]?){2}\\d{3}$" +
"|^(\\+\\d{1,3}( )?)?(\\d{3}[ ]?)(\\d{2}[ ]?){2}\\d{2}$";
String[] validPhoneNumbers = {"1234567890","123 456 7890", "(123)-456-7890", "+111 (123)-456-7890",
"123 456 789", "+111 123 456 789", "123 45 67 89", "+111 123 45 67 89"};
String[] validPhoneNumbers = {"2055550125","202 555 0125", "(202)-555-0125", "+111 (202)-555-0125",
"636 856 789", "+111 636 856 789", "636 85 67 89", "+111 636 85 67 89"};
Pattern pattern = Pattern.compile(patterns);
for(String phoneNumber : validPhoneNumbers) {