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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:53:23+00:00 2026-06-12T19:53:23+00:00

So I wanted to limit a textbox which contains an apartment number which is

  • 0

So I wanted to limit a textbox which contains an apartment number which is optional.

Here is the regex in question:

([0-9]{1,4}[A-Z]?)|([A-Z])|(^$)

Simple enough eh?

I’m using these tools to test my regex:
Regex Analyzer
Regex Validator

Here are the expected results:

  • Valid
    • “1234A”
    • “Z”
    • “(Empty string)”
  • Invalid
    • “A1234”
    • “fhfdsahds527523832dvhsfdg”

Obviously if I’m here, the invalid ones are accepted by the regex. The goal of this regex is accept either 1 to 4 numbers with an optional letter, or a single letter or an empty string.

I just can’t seem to figure out what’s not working, I mean it is a simple enough regex we have here. I’m probably missing something as I’m not very good with regexes, but this syntax seems ok to my eyes. Hopefully someone here can point to my error.

Thanks for all help, it is greatly appreciated.

  • 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-12T19:53:25+00:00Added an answer on June 12, 2026 at 7:53 pm

    You need to use the ^ and $ anchors for your first two options as well. Also you can include the second option into the first one (which immediately matches the third variant as well):

    ^[0-9]{0,4}[A-Z]?$
    

    Without the anchors your regular expression matches because it will just pick a single letter from anywhere within your string.

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

Sidebar

Related Questions

I wanted to display the remaining characters using a label beside my textbox just
I'm using the Facebook Javascript SDK. Is there a way to limit the number
I wanted to search through multiple rows and obtain the row that contains a
I know there is this question that is very similar, but I wanted to
I just wanted to know how to display the remaining characters in my textbox,
I have created a box2d world, and I wanted to limit the height of
I wanted to know how to have a 10 result limit on a redis
I'm using jQuery's Datepick maxDate option to limit the selection on the calendar to
I want to limit the number of buttons in the group of a ribbon
I have this binding <TextBlock HorizontalAlignment=Center Text={Binding Client.Name} Grid.Column=1/> Now I wanted to limit

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.