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

The Archive Base Latest Questions

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

I have the following REGEX that I’m serving up to java via an xml

  • 0

I have the following REGEX that I’m serving up to java via an xml file.

[a-zA-Z -\(\) \-]+

This regex is used to validate server side and client side (via javascript) and works pretty well at allowing only alphabetic content and a few other characters…

My problem is that it will also allow zero lenth strings / empty through.

Does anyone have a simple and yet elegant solution to this?

I already tried…

[a-zA-Z -\(\) \-]{1,}+

but that didn;t seem to work.

Cheers!

UPDATE FOLLOWING INVESTIGATION

It appears the code I provided does in fact work…

String inputStr = " ";
    String pattern = "[a-zA-Z -\\(\\) \\-]+";
    boolean patternMatched = java.util.regex.Pattern.matches(pattern, inputStr);
    if ( patternMatched ){
        out.println("Pattern MATCHED");
    }else{
        out.println("NOT MATCHED"); 
    }

After looking at this more closely I think the problem may well be within the logic of some of my java bean coding… It appears the regex is dropped out at the point where the string parse should take place, thereby allowing empty strings to be submitted… And also any other string… EEJIT that I am…

Cheers for the help in peer reviewing my initial stupid though….!

  • 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-02T16:32:11+00:00Added an answer on June 2, 2026 at 4:32 pm

    Have you tried this:

    [a-zA-Z -\(\) \-]+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following regex: ^[a-zA-Z](.*)[a-zA-Z]$ on both the Javascript and PHP side that
I have the following Regex that matches XAML tags: <[^<>]*> This would return both
In java, I have the following regex ([\\(\\)\\/\\=\\:\\|,\\,\\\\]) which is compiled and then used
Good Early Morning, I have the following python regex file that we established on
I have been trying to write a regex that will remove whitespace following a
I have the following data: abc def; ghi. This regex will match: ([a-z0-9A-ZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ ]*)\W
I have to validate using regex decimal number between 00.00 to 35.35 with following
Simple regex question. I have a string on the following format: this is a
I have the following Regex (in PHP) that I am using. '/^[a-zA-Z0-9&\'\s]+$/' It currently
I need to validate phone number in PHP. I have made following regex, but

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.