From 953b8d4640900045433599e8148d92990b8835a0 Mon Sep 17 00:00:00 2001 From: sergio41 Date: Fri, 24 Apr 2020 13:07:05 +0200 Subject: [PATCH] [BAEL-3944] Real like phone numbers --- .../baeldung/regex/PhoneNumbersRegexUnitTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/PhoneNumbersRegexUnitTest.java b/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/PhoneNumbersRegexUnitTest.java index edfa7a2c5e..620b7a9bae 100644 --- a/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/PhoneNumbersRegexUnitTest.java +++ b/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/PhoneNumbersRegexUnitTest.java @@ -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) {