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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:32:19+00:00 2026-05-31T11:32:19+00:00

I want to build a regular expression which allows following cases: M1 1AA B33

  • 0

I want to build a regular expression which allows following cases:

  • M1 1AA
  • B33 8TH
  • CR2 6XH
  • DN55 1PT
  • W1A 1HQ
  • EC1A 1BB

and should not allow, only a single letter or a single number. E.g:

  • A
  • 2
  • AA AAA
  • 22 343

Also how do i call this in javascript. I am currently using the RegEx

^[A-Z0-9 ]*[A-Z0-9][A-Z0-9 ]*$

Which validates all the above cases includin a single letter or single number.

Please help me how to use a javascript to be called on a textbox change n validate using above regular expression

  • 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-31T11:32:20+00:00Added an answer on May 31, 2026 at 11:32 am

    You’re close. One way to solve this problem would be

    ^[A-Z0-9 ]*[A-Z][A-Z0-9 ]*\d[A-Z0-9 ]*$|^[A-Z0-9 ]*\d[A-Z0-9 ]*[A-Z][A-Z0-9 ]*$
    

    which allows arbitrary letter, number, or space ([A-Z0-9 ]*) before, after, and between the letter and number, and allows either the letter to come first or the number to come first.

    However, there’s another way to solve this. You could use two regular expressions. First, check against the regular expression

    ^[A-Z0-9 ]*$
    

    which checks that you have only letters, numbers, and spaces. Then, check against the regular expression

    [A-Z][A-Z0-9 ]*\d|\d[A-Z0-9 ]*[A-Z]
    

    which checks for at least one letter ([A-Z]) and one number (\d), with both orders allowed. Note that this pattern doesn’t include the hat and dollar sign, so the letter and number can occur anywhere in the string.

    The two-regular-expression approach has the benefit of being easier to read and modify later.

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

Sidebar

Related Questions

I need to build ONE regular expression that can detect ALL the following strings
I have a complex regular expression I've built with code. I want to normalize
I'm trying to create regular expression that filters from the following partial text: amd64
I have been trying to build a regular expression but haven't been able to
I'm trying to build a Java regular expression to match .jar! The catch is
I am trying to build a regular expression to replace unresolved velocity variables with
I'd like to build a regular expression assembly of common regex I must use
I am trying to build a regular expression that does matches only string2 below.
I just want to create a regular expression out of any possible string. var
i want build a photography app with effects . e.g. old images with brown

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.