Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 6bd52f6

Browse files
committed
Regex Password Validation
1 parent 48f7e20 commit 6bd52f6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#Description
2+
3+
You need to write regex that will validate a password to make sure it meets the following criteria:
4+
5+
* At least six characters long
6+
* contains a lowercase letter
7+
* contains an uppercase letter
8+
* contains a number
9+
10+
Valid passwords will only be alphanumeric characters.
11+
12+
**Kata's link**: [Regex Password Validation](https://www.codewars.com/kata/regex-password-validation/)
13+
14+
#Best Practices
15+
16+
**First:**
17+
```
18+
function validate(password) {
19+
return /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$/.test(password);
20+
}
21+
```
22+
23+
**Second:**
24+
```
25+
function validate(password) {
26+
return /^[A-Za-z0-9]{6,}$/.test(password) &&
27+
/[A-Z]+/ .test(password) &&
28+
/[a-z]+/ .test(password) &&
29+
/[0-9]+/ .test(password) ;
30+
}
31+
```

0 commit comments

Comments
 (0)