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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:10:11+00:00 2026-06-02T15:10:11+00:00

I have this code with this regular expression: string lPattern = \\S*[a-zA-Z]+\\S*; System.Text.RegularExpressions.Regex lRegex

  • 0

I have this code with this regular expression:

string lPattern = "\\S*[a-zA-Z]+\\S*";

System.Text.RegularExpressions.Regex lRegex =
    new System.Text.RegularExpressions.Regex(lPattern);

if (!lRegex.IsMatch(phone))
{
    return true;
}

I want to make it so if space x space ” x ” is in the string is will also return true. How would I change this regular expression to include this? Thanks!

  • 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-02T15:10:13+00:00Added an answer on June 2, 2026 at 3:10 pm

    Apparently, this code is trying to validate a phone number by matching any alpha characters in the phone number — if a match is made, then the phone number is invalid.

    So you want any alpha character (optionally embedded inside non-whitespace characters, though these are listed as optional, so they’re actually irrelevant) except for the sequence x (space x space) to match and trigger failure.

    This sounds like you want accept the case of people embedding an extension into the phone number, as in: 123-123-1234 x 789

    .*([a-zA-Z])+(?<! x).*
    

    comes very close.

    EDIT: This uses a negative look-behind construction. (?<! allows the regex to keep going only if from the current match position, the previous characters do not match what’s inside the remainder of the parentheses. So, if there was a leading x it would fail the match.

    —

    Using this regex, the following don’t match:

    • 123-123-1234
    • 123-123-1234 x789
    • 123-123-1234 x 789

    But it does match:

    • 123-123a-1234
    • 123-123 asdfasdf 12312
    • 123-123x-123123
    • 123-123 xfasdf

    And the ones that match are invalid, by virtue of the ! in your if-statement.

    But having said that, your code would be much easier if you wrote the phone number validation as a positive validation (i.e. what do you allow), not a negative invalidation (what do you specifically avoid). By writing what you allow, you’ll be able to prevent edge cases much easier.

    For example, the following is not matched by both regex’s:

    • 123-###-1234
    • 123-!$#&^(##^#*@#(!@&#(#-1234

    and this would return true from your function. Is that what you really want?

    I strongly suggest positive validation, not negative invalidation.


    EDIT: @Aprillion suggests this previous linked question: A comprehensive regex for phone number validation

    This shows how complicated phone number validation can be (especially if you’re validating for more than 1 country). There’s a lot of good suggestions in there, though it’s not be the be-all-end-all summary. My inclination would be on the front-end to allow only digits (w/ an optional free-from comment field) for phone number entry.

    I must admit also, that, it does give me a little less confidence on positive validation — especially if you have to deal w/ an arbitrary international #.

    A lot would be dependent upon the OP’s real requirements.

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

Sidebar

Related Questions

I have a regular expression: l:([0-9]+) This should match this string and return three
I have some ActionScript code that splits a string using Regular Expression and lets
I have this code private void writeReport(IReport report, string reportName) { string reportString =
I have this code: def setVelocity (x, y, yaw) setVelocity (Command2d.new(x,y,yaw)) end def setVelocity
I have this situation(Java code): 1) a string such as : A wild adventure
I want know, what regular expression should I have for my string. My string
I have a text containing expressions that may be generated by the regular expression
Here's my regular expression that I have for this. I'm in Ruby, which —
I have a string with some HTML code in, for example: This is <strong
I have a regular expression in my code to match on the keys (control

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.