Codecademy Forums

The pattern of the input for the password setting

I am trying to make the password setting feature for membership setting page in the website that I am practicing to develope.
Here comes the problem even though I found the solution, but it will be nice if I can really understand the code.

<input type="password" id="pwd" name="password" maxlength="12" size="14" placeholder="6~12enlgish and number" required pattern="(?=^[A-Za-z0-9]{6,12}$)((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]))^.*$"

The part I am not fully understand is below:

pattern="(?=^[A-Za-z0-9]{6,12}$)((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]))^.*$

What I understand which learned from the HTML section in the Codecademy course ealier:

[A-Za-z0-9]means A to Z, a to z and 0 to 9
{6,12} means the passwords needs at least 6 letters and maximal 12 letters~
According to the sample I found online that I am trying to learn, this whole pattern setting is at least one capital letter for the setting~~

I wonder what if I want to set up the password follow the rules like these below:

  1. two English letters only
  2. one Capital English letter
  3. including one ! or other special characters
    4.at least 4 numbers

Please to help me! Thanks, ~~~ I am kind of stuck here a while~~~XD really want to understand ~

https://regex101.com/

I’m no regex expert. But I think the capture group doesn’t need to be there.
And then you could add similar lookahead conditions for those things, there’s already some counting shown in what you have there.
You might be able to use a javascript function for the validation instead, might be a lot easier to deal with, especially for more complicated conditions.

2 Likes

That’s kind of cool~~~ I will give a try~~~ although not really understand the package of code yet~~~ it will definitely help
Thank you

1 Like

I will look at the JS function to do so ~~~
and I found that website really explained the code well~
Thank you

@ionatan I was wondering if that means the expression is fine.


image

You’re the one who defines what “fine” means, aren’t you

4 Likes

In general, I find that when it comes to regex if you don’t fully understand either regex in general or what your expression is doing then you ought to find a different way of doing what you want.

Regex is an amazingly powerful thing, but it can soooooo easily go wrong if you’re not incredibly careful.

2 Likes

Thanks for telling me that~~

1 Like