Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7566495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:25:47+00:00 2026-05-30T14:25:47+00:00

I am using the following code to validate a phone number. The requirements are

  • 0

I am using the following code to validate a phone number. The requirements are the phone number should be inbetween 10-25 characters length, should include hypen(-),period(.), parentheses ().

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class ValidatePhoneNumber {

public static void main(String[] argv) {

    String phoneNumber = "6058.8()6-05888,9994567";
    System.out.println(phoneNumber.length());
    //String sPhoneNumber = "605-88899991";
    //String sPhoneNumber = "605-888999A";
    String regex = "^[0-9.()-]{10,25}$";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(phoneNumber);

    if (matcher.matches()) {
        System.out.println("Phone Number Valid");
    } else {
        System.out.println("Phone Number must be in the form XXX-XXXXXXX");
    }
  }
 }

I checked the validations and its working fine, I want to add a whitespace character “\s” as well so that in between the phone number there can be whitespace as well. But getting errors while adding “\s” in regex.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:25:49+00:00Added an answer on May 30, 2026 at 2:25 pm

    Please, look at standards like ITU E.164 or IETF RfC 3966. Don’t assume that every country has the same conventions and number lengths.

    Here’s the relevant ABNF part out of RfC 3966

    global-number-digits = "+" *phonedigit DIGIT *phonedigit
    phonedigit           = DIGIT / visual-separator 
    visual-separator     = "-" / "." / "(" / ")"
    DIGIT = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
    

    We recently had a huge trouble with a device that didn’t let the user enter the ‘+’ as part of a phone number.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to display phone number in text field in
I am using regular expressions to validate user input. The following code collects a
I am using the following code to validate an an XML file against a
I'm using the following code to validate the text in JTextFields Text1 and Text2.
I'm using the following code to validate a 'set' of input fields . 4
Im Using the following code to validate (poorly, I know) a form's $_POST[] ed
I want to send email using the php code, Following is the code should
i want to validate all inputs using class name i'm using following code $('#submitbutton').click(function()
i have the following code to validate my file name entered using regular expression
I'm using the following Coffeescript code to validate that initialization of one backbone.js view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.