Match Phone Number 2 : Phone Number « Regular Expressions « Java






Match Phone Number 2

 

public class Main {
  public static void main(String args[]) {
    String phone = "(111)-111-1111";
    String phoneNumberPattern = "(\\d-)?(\\d{3}-)?\\d{3}-\\d{4}";
    System.out.println(phone.matches(phoneNumberPattern));
  }
}

   
  








Related examples in the same category

1.Match phone numberMatch phone number