Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Set minimum length restriction to Password Validation - Regular Expression

I have a regular expression for validating passwords.

/[\w\d]*(([0-9]+.*[A-Za-z]+.*)|[A-Za-z]+.*([0-9]+.*))/

This regex matches any words which contain letters and numbers in them.

I want to add a minimum length restriction as well, I got to know we can use {4,} to add a minimum length of 4.

But I am not able to figure out how to add this minimum length to the whole expression.

For example: The above regex matches p12 as valid.

I dont want it to match words with letters and numbers with a length of less than 4.

I tried this, but this did not work

/[\w\d]*(([0-9]+.*[A-Za-z]+.*)|[A-Za-z]+.*([0-9]+.*)){4,}/

Any help with respect to adding minimum length restriction to the whole expression would be appriciated.

Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Using \w also matches \d so this parts [\w\d]* can be written as just \w*

If you want to match only word characters, you could use for example 2 assertions for the char a-z and a digit.

Using a case insensitive pattern:

/^(?=[^\d\n]*\d)(?=[^a-z\n]*[a-z])\w{4,}$/i

Regex demo

const regex = /^(?=[^\d\n]*\d)(?=[^a-z\n]*[a-z])\w{4,}$/;
[
  "p12",
  "1234",
  "abcs",
  "p123"
].forEach(s => console.log(`${s} --> ${regex.test(s)}`));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!