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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:56:22+00:00 2026-05-11T21:56:22+00:00

^([a-zA-Z0-9!@#$%^&*|()_\-+=\[\]{}:;\’,<.>?\/~`]{4,})$ Would this regular expression work for these rules? Must be atleast 4 characters

  • 0
^([a-zA-Z0-9!@#$%^&*|()_\-+=\[\]{}:;\"',<.>?\/~`]{4,})$

Would this regular expression work for these rules?

  • Must be atleast 4 characters
  • Characters can be a mix of alphabet (capitalized/non-capitalized), numeric, and the following characters: ! @ # $ % ^ & * ( ) _ – + = | [ { } ] ; : ‘ ” , < . > ? /

It’s intended to be a password validator. The language is PHP.

  • 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-11T21:56:22+00:00Added an answer on May 11, 2026 at 9:56 pm

    Yes?

    Honestly, what are you asking for? Why don’t you test it?

    If, however, you want suggestions on improving it, some questions:

    1. What is this regex checking for?
    2. Why do you have such a large set of allowed characters?
    3. Why don’t you use /\w/ instead of /0-9a-zA-Z_/?
    4. Why do you have the whole thing in ()s? You don’t need to capture the whole thing, since you already have the whole thing, and they aren’t needed to group anything.

    What I would do is check the length separately, and then check against a regex to see if it has any bad characters. Your list of good characters seems to be sufficiently large that it might just be easier to do it that way. But it may depend on what you’re doing it for.

    EDIT: Now that I know this is PHP-centric, /\w/ is safe because PHP uses the PCRE library, which is not exactly Perl, and in PCRE, \w will not match Unicode word characters. Thus, why not check for length and ensure there are no invalid characters:

    if(strlen($string) >= 4 && preg_match('[\s~\\]', $string) == 0) {
      # valid password
    }
    

    Alternatively, use the little-used POSIX character class [[:graph:]]. It should work pretty much the same in PHP as it does in Perl. [[:graph:]] matches any alphanumeric or punctuation character, which sounds like what you want, and [[:^graph:]] should match the opposite. To test if all characters match graph:

    preg('^[[:graph:]]+$', $string) == 1
    

    To test if any characters don’t match graph:

    preg('[[:^graph:]]', $string) == 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
&mobile=0400000000¬es=this+is+a+test The error is above You will see that the following has occurred ¬es
P&G P&ampG P&amp;G All these are same. Is the use of special entities only
UPDATE & SOLUTION : Everyone, for whoever has this problem in the future, I
#&q=car&category=Car%20Audio%2CAccessories&brand= I borrowed a this function from a previous question asked on SO: function
&mdash; or &#8212; Is there a difference between these? Is one better-supported than the
&gt; &lt;strong&gt; HTML tags, and much more (these 3 are just examples) Is there
& is a reserved character in html therefore everywhere I have url's pointing to

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.