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

  • Home
  • SEARCH
  • 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 6922405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:24:06+00:00 2026-05-27T10:24:06+00:00

How would you modify this regex to only allow letters and numbers? I thought

  • 0

How would you modify this regex to only allow letters and numbers?

I thought by putting that it must have at least 2 uppercase letters, lowercase letters and digits, that it would limit the expression to just those types of characters. But it allows unwanted characters like tildes and such.

/^[\s]*((?=([^\s]*\d){2,})(?=([^\s]*[a-z]){2,})(?=([^\s]*[A-Z]){2,})[^\s]{8,16})[\s]*$/
  • 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-27T10:24:06+00:00Added an answer on May 27, 2026 at 10:24 am

    Here’s a way to do it using a few needles. fiddle

    alert( verify('AbcdeFghij123') );
    alert( verify('Abcdeghij123') ); // Only 1 capital
    alert( verify('AbcdeFghij') ); // No numbers
    alert( verify('ABCDEF123') ); // No lowercase
    alert( verify('Abc~~ghij123') ); // Tilde
    alert( verify('') ); // Blank
    
    function verify(pass) {
        return /^[A-Za-z0-9]+$/.test(pass)
            && /[A-Z][^A-Z]*[A-Z]/.test(pass)
            && /[a-z][^a-z]*[a-z]/.test(pass)
            && /[0-9][^0-9]*[0-9]/.test(pass);
    }
    

    If you want to limit the size to being between X and Y replace /^[A-Za-z0-9]+$/ with /^[A-Za-z0-9]{X,Y}$/. Pretty simple, eh?

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

Sidebar

Related Questions

We have a customer that would like to modify application user messages that we
I have code, similar to the following, that I would like to modify: Sub
I'm currently using this regex ^[A-Z0-9 _]*$ to accept letters, numbers, spaces and underscores.
I have this simple regex, [\d]{1,5} that matches any integer between 0 and 99999.
I have a String which I would like to modify in some way. For
For a Rails app, I would like to overload or modify Kernel::load such that
I need to modify this regex href=\(.*)\ which matches this... href=./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306 To NOT match
I'm trying to write a bash script that would modify all occurrences of a
I have a set of 4 massive CSV files that I need to modify.
I have a function that should be passed a string with two numbers (as

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.