1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<html>
	<head>	
		<title>PasswordChecker</title>
	</head>
	<body id="body">
		<form action="javascript:void(0);" id ="exampleForm">
			<input type="password" id="examplePass"/>
			<input type="submit"/>
		</form>
	</body>
	<script>
		document.getElementById("exampleForm").onsubmit = function() {
			var passwordRegex = /\W+/;
			var passwordRegex2 = /.{6,}/;
			var passwordRegex3 = /\d+/;
			
			var str = document.getElementById("examplePass").value;
			if(!passwordRegex3.test(str) || !passwordRegex2.test(str) || !passwordRegex.test(str)){
				console.log("Regex didn't match");
				var notify = document.getElementById("notify");
				if (notify === null){
					notify = document.createElement("p");
					notify.textContent = "Passwords need to be longer than 6 characters and consist of at least 1 non-word characters and 1 digits, punctuation characters and digits.";
					notify.id = "notify";
					
					var body = document.getElementById("body");
					body.appendChild(notify);
				}
			}
		};
	</script>
</html>