You can use simple String.matches(regex) to test any string against a regex pattern instead of using Pattern and Matcher classes.

Sample:

boolean isValid = phoneString.matches(regexPattern);

Find more examples

Here is the regex pattern as per your input string:

\+\d(-\d{3}){2}-\d{4}

Online demo


Better use Spring validation annotation for validation.

Example

Answer from Braj on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › program-to-check-valid-mobile-number
Program to check valid mobile number - GeeksforGeeks
January 21, 2026 - This method validates the mobile number manually, without using regular expressions. It is useful for beginners who want to understand logic-based validation.
🌐
Javatpoint
javatpoint.com › mobile-number-validation-in-java
Mobile Number Validation in Java - Javatpoint
Mobile Number Validation in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
Discussions

validation - Validate phone number without regex in Java Spring MVC - Stack Overflow
I have form with text input element for phone number, Phone: More on stackoverflow.com
🌐 stackoverflow.com
August 18, 2016
regex - phone Number validation in java - Stack Overflow
I want to validate a phone number in such Way :- The field should allow the user to enter characters and should auto-correct. So an entry of "+1-908-528-5656" would not create an error for the use... More on stackoverflow.com
🌐 stackoverflow.com
Phone Number validation | OutSystems
I am doing a reactive web application to store the data of an employee locally (I am not using database .. I am using structures) , while storing the phone number I need to validate it . The phone number should not contain alphabits and special charecters and it should only contain 10 digits . More on outsystems.com
🌐 outsystems.com
May 24, 2023
regex - Java Regular Expressions to Validate phone numbers - Stack Overflow
In the following code I am trying to get the output to be the different formatting of phone numbers and if it is either valid or not. I figured everything out but the Java Regular Expression code o... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Akamai TechDocs
techdocs.akamai.com › identity-cloud › docs › validate-mobile-device-numbers
Validate a mobile number
For example, the following libphonenumber function returns a Boolean value (true or false) that tells you whether a given phone number (number) is valid for the specified locale (regionCode): ... No regular expression required.
🌐
Stack Overflow
stackoverflow.com › questions › 39009531 › validate-phone-number-without-regex-in-java-spring-mvc
validation - Validate phone number without regex in Java Spring MVC - Stack Overflow
August 18, 2016 - Phone number validation in Java · 23 · Validate Mobile Number using Hibernate annotation · 0 · Input validation phone number · 1 · JSF telephone numbers regular expression · 0 · Custom validator for a phone number in JSF · 0 · java.util.regex Validating Phone numbers ·
Top answer
1 of 9
6

You can use simple String.matches(regex) to test any string against a regex pattern instead of using Pattern and Matcher classes.

Sample:

boolean isValid = phoneString.matches(regexPattern);

Find more examples

Here is the regex pattern as per your input string:

\+\d(-\d{3}){2}-\d{4}

Online demo


Better use Spring validation annotation for validation.

Example

2 of 9
4
// The Regex not validate mobile number, which is in internation format.
// The Following code work for me. 
// I have use libphonenumber library to validate Number from below link.
// http://repo1.maven.org/maven2/com/googlecode/libphonenumber/libphonenumber/8.0.1/
//  https://github.com/googlei18n/libphonenumber
// Here, is my source code.

 public boolean isMobileNumberValid(String phoneNumber)
    {
        boolean isValid = false;

        // Use the libphonenumber library to validate Number
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        Phonenumber.PhoneNumber swissNumberProto =null ;
        try {
            swissNumberProto = phoneUtil.parse(phoneNumber, "CH");
        } catch (NumberParseException e) {
            System.err.println("NumberParseException was thrown: " + e.toString());
        }

        if(phoneUtil.isValidNumber(swissNumberProto))
        {
            isValid = true;
        }

        // The Library failed to validate number if it contains - sign
        // thus use regex to validate Mobile Number.
        String regex = "[0-9*#+() -]*";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(phoneNumber);

        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }
🌐
OutSystems
outsystems.com › forums › discussion › 88524 › phone-number-validation
Phone Number validation | OutSystems
May 24, 2023 - I am doing a reactive web application to store the data of an employee locally (I am not using database .. I am using structures) , while storing the phone number I need to validate it . The phone number should not contain alphabits and special charecters and it should only contain 10 digits .
🌐
Medium
olubunmi-alegbeleye.medium.com › validating-phone-numbers-using-googles-libphonenumber-library-4c7066d8a0b6
Validating phone numbers using Google’s libphonenumber library | by Olubunmi Alegbeleye | Medium
January 31, 2023 - In this short article, we saw in action a powerful library that replaces all those ugly regular expressions when validating phone numbers. ... You may need to format the validated phone number in a different format. That is where the PhoneNumberUtil’s formatting ability comes in. Just do this. In this example, we format the phone number as an E.164 number: //Java String internationalFormat = phoneNumberUtil.format(rawPhoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
Find elsewhere
🌐
AbstractAPI
abstractapi.com › api guides, tips & tricks › 5 ways to implement phone number validation in java
5 Ways to Validate Phone Numbers in Java
August 8, 2025 - Phone number validation is a fundamental step for ensuring data integrity in Java applications. We'll walk through four distinct methods for validation, providing code for each.
🌐
Medium
medium.com › @dfs.techblog › contact-number-normalization-in-java-5073c31d8100
Contact Number Normalization in Java | by Comviva MFS Engineering Tech Blog | Medium
January 31, 2025 - By using libphonenumber, you can easily parse, validate, and format phone numbers in a standardized way, reducing errors, improving data quality, and ensuring compatibility with external services.
Top answer
1 of 5
24

Basically, you need to take 3 or 4 different patterns and combine them with "|":

String pattern = "\\d{10}|(?:\\d{3}-){2}\\d{4}|\\(\\d{3}\\)\\d{3}-?\\d{4}";
  • \d{10} matches 1234567890
  • (?:\d{3}-){2}\d{4} matches 123-456-7890
  • \(\d{3}\)\d{3}-?\d{4} matches (123)456-7890 or (123)4567890
2 of 5
8

Considering these facts about phone number format:-

  1. Country Code prefix starts with ‘+’ and has 1 to 3 digits
  2. Last part of the number, also known as subscriber number is 4 digits in all of the numbers
  3. Most of the countries have 10 digits phone number after excluding country code. A general observation is that all countries phone number falls somewhere between 8 to 11 digits after excluding country code.
String allCountryRegex = "^(\\+\\d{1,3}( )?)?((\\(\\d{1,3}\\))|\\d{1,3})[- .]?\\d{3,4}[- .]?\\d{4}$";

Let's break the regex and understand,

  • ^ start of expression
  • (\\+\\d{1,3}( )?)? is optional match of country code between 1 to 3 digits prefixed with '+' symbol, followed by space or no space.
  • ((\\(\\d{1,3}\\))|\\d{1,3} is mandatory group of 1 to 3 digits with or without parenthesis followed by hyphen, space or no space.
  • \\d{3,4}[- .]? is mandatory group of 3 or 4 digits followed by hyphen, space or no space
  • \\d{4} is mandatory group of last 4 digits
  • $ end of expression

This regex pattern matches most of the countries phone number format including these:-

        String Afghanistan      = "+93 30 539-0605";
        String Australia        = "+61 2 1255-3456";
        String China            = "+86 (20) 1255-3456";
        String Germany          = "+49 351 125-3456";
        String India            = "+91 9876543210";
        String Indonesia        = "+62 21 6539-0605";
        String Iran             = "+98 (515) 539-0605";
        String Italy            = "+39 06 5398-0605";
        String NewZealand       = "+64 3 539-0605";
        String Philippines      = "+63 35 539-0605";
        String Singapore        = "+65 6396 0605";
        String Thailand         = "+66 2 123 4567";
        String UK               = "+44 141 222-3344";
        String USA              = "+1 (212) 555-3456";
        String Vietnam          = "+84 35 539-0605";

Source:https://codingnconcepts.com/java/java-regex-for-phone-number/

🌐
UI Bakery
uibakery.io › regex-library › phone-number-java
Phone number regex Java
While validation of phone numbers using regex can give a possibility to check the format of the phone number, it does not guarantee that the number exists. There might be also an option to leave a phone number field without any validation since some users might have:
🌐
Baeldung
baeldung.com › home › java › using libphonenumber for phone number validation and conversion
Using libphonenumber for Phone Number Validation and Conversion | Baeldung
November 24, 2025 - In this quick tutorial, we’ll see how to use Google’s open-source library libphonenumber to validate phone numbers in Java.
🌐
Stack Abuse
stackabuse.com › java-regular-expressions-validate-phone-number
Java Regular Expressions - Validate Phone Number
November 23, 2021 - In this short article, we'll take a look at how to validate a phone number in Java, using the regex package and multiple Regular Expressions.
🌐
Baeldung
baeldung.com › home › java › validate phone numbers with java regex
Validate Phone Numbers With Java Regex | Baeldung
January 8, 2024 - As we’ve seen, a valid phone number can take on several different formats. Therefore, we may want to check if our String complies with any one of these formats. In the last section, we started with a simple expression and added more complexity to achieve the goal of covering more than one format. However, sometimes it’s not possible to use just one expression. In this section, we’ll see how to join multiple regular expressions into a single one.
🌐
GitHub
github.com › google › libphonenumber
GitHub - google/libphonenumber: Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers. · GitHub
Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers. - google/libphonenumber
Starred by 17.9K users
Forked by 2.2K users
Languages   C++ 53.4% | Java 29.9% | JavaScript 15.8% | CMake 0.4% | C 0.2% | Closure Templates 0.1%
🌐
TutorialsPoint
tutorialspoint.com › phone-number-validation-using-java-regular-expressions
Phone Number validation using Java Regular Expressions
public class MatchPhoneNumber { public static void main(String args[]) { isPhoneValid("1-999-585-4009"); isPhoneValid("999-585-4009"); isPhoneValid("1-585-4009"); isPhoneValid("585-4009"); isPhoneValid("1.999-585-4009"); isPhoneValid("999 585-4009"); isPhoneValid("1 585 4009"); isPhoneValid("111-Java2s"); } public static boolean isPhoneValid(String phone) { boolean retval = false; String phoneNumberPattern = "(\\d-)?(\\d{3}-)?\\d{3}-\\d{4}"; retval = phone.matches(phoneNumberPattern); String msg = "NO MATCH: pattern:" + phone + "\r\n regex: " + phoneNumberPattern; if (retval) { msg = " MATCH: pattern:" + phone + "\r\n regex: " + phoneNumberPattern; } System.out.println(msg + "\r\n"); return retval; } }
🌐
Stack Overflow
stackoverflow.com › questions › 50819878 › java-regex-phone-number-validation-in-java
Java Regex Phone Number validation In Java - Stack Overflow
Could you please tell me what is the Regex for (XXX) XXXXXXX in Java? I have tried the below, however they seem to be wrong. For example- (123) 4567890 String regex="/^(?:\(\d{3}\)|\d{3}-)\d{3}-...
🌐
Corteza
forum.cortezaproject.org › 🧩 low-code development
Phone number validation - 🧩 Low-Code Development - Corteza
December 30, 2021 - Hi, Is there a way to validate a record field as being an actual phone number. If I could validate a string as being exactly 10 digits that would be enough for now. But even in the CRM app it is possible to enter alphab…
🌐
CodingNConcepts
codingnconcepts.com › java › java-regex-to-validate-phone-number
Java Regex to Validate Phone Number - Coding N Concepts
May 27, 2020 - In this article, we’ll learn how to validate mobile phone number of different country’s format using Java Regex (Regular Expressions)