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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:42:34+00:00 2026-06-11T11:42:34+00:00

I have a regular expression to validate a password to contain numbers, lowercase and

  • 0

I have a regular expression to validate a password to contain numbers, lowercase and uppercase characters.

The one below works fine. But when I use this in jQuery Validation:

txtPassword: {
    required: true,
    regex: Regex
}

Regex = (?=^.{8,16}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+}{":;/'?/>.<,])(?!.*\s).*$

But the issue is single quote ' in Javascript. Can some body please help me to resolve this? Thankyou.

  • 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-11T11:42:35+00:00Added an answer on June 11, 2026 at 11:42 am

    There are several things that need to fixed in this regex:

    • In your lookahead checks for the password, you have a period without
      a quantifier. Hence it will always fail that check. For e.g., for the
      number check, you should have (?=.*\d) instead of (?=.\d).
    • You do not escape characters with a forward-slash /, instead you
      use a backslash \. You have it escaped incorrectly with a
      forwardslash in the last character class.
    • The only special characters or metacharacters inside a character
      class are the closing bracket (]), the backslash (\), the caret (^)
      and the hyphen (-). Hence it is not due to the single quote. The culprit is your caret which is not escaped.

    Try this regex where the caret ^ is escaped instead of the quote ':

    (?=^.{8,16}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%\^&*()_+}{":;'?/>.<,])(?!.*\s)^.*$
    

    I am assuming by your question, you meant a Regexp to validate a password with:

    • at least 1 number
    • at least 1 lowerchase character
    • at least 1 uppercase character
    • at least 1 special character out of the set !@#$%^&*()_+}{":;'?/>.<,
    • length between 8 and 16 characters

    If this is true, please update your question with the clarified requirement.


    Play with the regex in RegexPal


    jQuery based code. Fiddle with this here:

    var regex = /(?=^.{8,16}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%\^&*()_+}{":;'?/>.<,])(?!.*\s)^.*$/g;
    //if(regex.test($('#txtPassword').val())){ alert('Match'); }else{alert('No Match')}
    if (regex.test('P@sSw0rD')) {
        alert('Match');
    } else {
        alert('No Match');
    }​
    
    • 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 to validate the dates and it works fine, this
I have this regular expression below to validate a security question where some one
I have a regular expression to validate a input value. At this point I
I have this light regular expression to validate the coordinates: ^([0-9.,-]+){18,20}$^ . If the
i want a regular expression to validate string to have only text,operators and these
I have a regular expression ( \d{4}\w{3}(0[1-9]|[12][0-9]|3[01])([01][0-9]|2[0-3])([0-5][0-9]){2} ) that I need to validate the
I'm trying to validate mm-dd-(2012~2099) date format. I have the following regular expression. ^(0[1-9]|1[0-2])-(0[1-9]|[10-31])-(20[12-99])$
I have a regular expression ^[a-zA-Z+#-.0-9]{1,5}$ which validates that the word contains alpha-numeric characters
Currently I have this regular expression to validate letters, dash and spaces. /^[a-zA-Z-\s]*$/ Now,
I need a regular expression to validate string with one or more of these

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.