-
Notifications
You must be signed in to change notification settings - Fork 0
/
task4.php
56 lines (42 loc) · 1.33 KB
/
task4.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<body>
<h1>Task 4</h1>
<?php
//Task 4 (a)
class Validate{
private static $userRegex = "/^([a-z]){4}$/";
private static $passwordRegex = "/^([0-9]){6,8}$/";
public static function ValidateUser($user){
return preg_match(Validate::$userRegex, $user);
}
public static function ValidatePassword($password){
return preg_match(Validate::$passwordRegex, $password);
}
}
?>
<h2>Task 4(a) :</h2>
<p>Validate username and password</p>
<p>
<?php
echo "<b>Username </b> <br>";
echo "Validate abcd - " . Validate::ValidateUser('abcd') . "<br>";
echo "Validate abcde - " . Validate::ValidateUser('abcde') . "<br>";
echo "<br>";
echo "<b>Password </b> <br>";
echo "Validate 1234567 - " . Validate::ValidatePassword('1234567') . "<br>";
echo "Validate abcde - " . Validate::ValidatePassword('abcde') . "<br>";
echo "<br>";
?>
</p>
<h2>Task 4(b) :</h2>
<p>/^[01]?\d\/[0-3]\d\/\d{4}$/</p>
<p>
<?php
echo "Validate 10/10/2011 - " . preg_match("/^[01]?\d\/[0-3]\d\/\d{4}$/", "11/11/1111") . "<br>";
echo "Validate 3/3/1981 - " . preg_match("/^[01]?\d\/[0-3]\d\/\d{4}$/", "aa/aa/aaaa") . "<br>";
echo "<br>";
?>
</p>
</body>
</html>