JS Regex – String with at least 6 characters, one digit and one number. No whitespaces, no special characters, and only letters and digits [duplicate]


I need a Regex expression for words with

  1. at least 6 characters
  2. only letters and digits
  3. at least one digit
  4. at least one letter

I have been testing this one

 /^((?=.*d)(?=.*[a-zA-Z]))w{6,}$/

but fails with

_1234aa
const re = /^((?=.*d)(?=.*[a-zA-Z]))w{6,40}$/;

const password1 = "_1234aa";
console.log(re.test(password1)); // should be false

const password2 = "1234aA";
console.log(re.test(password2)); // works fine (true)

const password3 = "aaaaaa";
console.log(re.test(password3)); // works fine (false)

const password4 = "1234-aa";
console.log(re.test(password4)); // works fine (false)

Source: JavaSript – Stack Overflow

November 25, 2021
Category : News
Tags: javascript | regex

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.