I have begun studying Web Development and I'm stuck at pattern or regexp because I cannot fully understand it or how do I put rules in it's syntax, can someone explain it to me?
<label for="password2">Password: </label>
<input id="password2" type="password" placeholder="password here"
pattern="[0-9a-zA-Z]{8,12}"
title="Please enter a password 8-12 alpha numeric characters" required>
In the above example I have understood the following in it's pattern:
0-9 <- You can insert numbers through 0 to 9
a-z <- You can insert lowercase letters from a to z
A-Z <- You can isert uppercase letters from A to Z
{8,12} <- Password must be at least 8 and 12 maximum characters
So far, so good.
But how do I add rules such as:
1) Please insert at least a symbol or more such as !, @, #, $
2) Input at least an uppercase letter or more
3) Input at least 3 numbers
4) Exclude these symbols such as: &, *
In W3Schools they have the following example:
<form action="/action_page.php">
Password: <input type="password" name="pw" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters">
<input type="submit">
</form>
What is and what does it do:
1) (?=.\d)
2) (?=.[a-z]) <- This must be "use at least one lowercase letter", but how can you define how many lowercase letters you want?
3) (?=.*[A-Z]) <- And this is for uppercase
Also another example is from MDN
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password
<label for="ssn">SSN:</label>
<input type="password" id="ssn" inputmode="numeric" minlength="9" maxlength="12"
pattern="(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -])?(?!00)\d\d\3(?!0000)\d{4}"
required autocomplete="off">
<br>
<label for="ssn">Value:</label>
<span id="current"></span>
Which uses the following rules: (?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -])?(?!00)\d\d\3(?!0000)\d{4}"
Can someone break it down and explain it? and is the above syntax html or something else?
I'm sorry for the long post, you don't have to answer to everything I asked.
I just want to have a clear understanding.
I know I may not have to use anything from the above because you can't trust any user in the front end and I may use JavaScript for the rules above.
"All users are guilty until proven innocent"
Thanks.