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 8576795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:00:27+00:00 2026-06-11T20:00:27+00:00

For example, I want to validate a string containing a phone number to enforce

  • 0

For example, I want to validate a string containing a phone number to enforce first a ‘+’ followed by 2 digits, then a sequence of either digits or a single instance of either a hyphen or a space. The string must end with a digit.

I currently have:

<xs:pattern value="\+\d{2}[- ]?[\d -]+[\d]"/>

but this does not restrict repetition of the spaces or hyphens within the string. How can this be achieved?

  • 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-06-11T20:00:28+00:00Added an answer on June 11, 2026 at 8:00 pm

    You say “… then a sequence of either digits or a single instance of either a hyphen or a space” — take literally, that suggests that the following are all acceptable (I quote the strings when they end with a space):

    "+01 "
    +01-
    +4312345678912345678900
    

    Looking at your code, I guess that you were speaking informally, and what you want could better be described as a plus, two digits, and then a sequence of digits interrupted by at most one hyphen or space, which must not be final. If that’s an accurate paraphrase, you might try

    \+\d{2}\d*[- ]?\d+
    

    If you want to allow up to one hyphen and up to one space, it gets a lot more complicated, but it’s still expressible. Assuming you don’t want an empty sequence of digits to be acceptable:

    \+\d{2}(\d+|(\d*(-\d+| \d+)?))
    

    [Not tested.]

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

Sidebar

Related Questions

I want to validate an input string against a regular expression and then split
I want to validate Winforms text box with regex. The input sting example: ZX1
I want to validate any string that contains çÇöÖİşŞüÜğĞ chars and starting at least
For example I want to use custom logger: logger = require('basic-logger'), logger.setLevel('info') var customConfig
For example: I want to know if there are images in a directory (eg.
For example: I want: if file1 exists: CLEAN_SRC = *.h file3 else CLEAN_SRC =
for example : I want to remove all highlighted tags alt text http://shup.com/Shup/299976/110220132930-My-Desktop.png
Example: Suppose in the following example I want to match strings that do not
Here's a contrived example: I want to divide two numbers and I need to
I want to round a value in Twig. Example: I want to display 80.5555

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.