Real like phone numbers
@@ -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) {
