-
Notifications
You must be signed in to change notification settings - Fork 0
/
js6.php
163 lines (152 loc) · 5.9 KB
/
js6.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html>
<?php
// Variables
$school = "POLYTECHNIC UNIVERSITY OF THE PHILIPPINES";
$course = "BSCpE";
$yearlevel = "4th Year";
$dateofbirth = "01/04/1999";
$gender = "Male";
// Constants
define('NAME','THEO LEONARD P. TEJADA');
define('STUDENT NUMBER', '2015-01331-MN-0');
define('ADDRESS','Navotas City');
define('EMAILADDRESS','tlp.tejada@iskolarngbayan.pup.edu.ph');
define('CONTACTNUMBER','+639052895824');
define('WEBADDRESS','kkshinichi.me');
define('LABTITLE', 'Javascript Hands-on Activity No. 6');
define('DESCRIPTION', "Credit Card Format Checker");
?>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php echo LABTITLE; ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="js2.css">
</head>
<body onload="main()">
<div class="header">
<h1>WebDevScrims</h1>
</div>
<div class="menu">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="lab2.php">Laboratory Exercises</a></li>
<li><a href="js1.php">JavaScript Activities</a>
<li><a href="OurTeam.php">Our Team</a></li>
</ul>
</div>
<div class="row">
<div class="leftcolumn">
<ul>
<p>JavaScript Hands-on</p>
<li><a href="js1.php">JavaScript Hands-on Activity 1</a></li>
<li><a href="js2.php">JavaScript Hands-on Activity 2</a></li>
<li><a href="js3.php">JavaScript Hands-on Activity 3</a></li>
<li><a href="js4.php">JavaScript Hands-on Activity 4</a></li>
<li><a href="js5.php">JavaScript Hands-on Activity 5</a></li>
<li><a href="js6.php">JavaScript Hands-on Activity 6</a></li>
<li><a href="js7.php">JavaScript Hands-on Activity 7</a></li>
</ul>
</div>
<div id="rightcolumn">
<script>
function main(){
var name = prompt("Please Enter the Cardholder's Name:", "e.g. JUAN DELA CRUZ");
var cardType = prompt("Please Enter the Card Provider:", "e.g. MasterCard; JCB");
var cardNum = prompt("Please Enter the Card Number:", "e.g. XXXXXXXXXXXXXXXX");
var exDate = prompt("Please Enter the Card Expiry Date:", "e.g. MM/YY");
document.getElementById('name').innerHTML = "Cardholder's Name: " + name;
document.getElementById('cardType').innerHTML = 'Credit Card Provider: ' + cardType;
document.getElementById('cardNum').innerHTML = 'Credit Card Number: ' + cardNum;
document.getElementById('exDate').innerHTML = 'Expiry Date: ' + exDate;
var amex = /^(?:3[47][0-9]{13})$/;
var visa = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/;
var mc = /^(?:5[1-5][0-9]{14})$/;
var jcb = /^(?:(?:2131|1800|35\d{3})\d{11})$/;
var expd = /^(0[1-9]|1[0-2])\/?([0-9]{4}|[0-9]{2})$/;
var card = cardNum.toString();
var expTest;
switch(cardType) {
case 'American Express':
case 'Amex':
case 'AMEX':
var amexTest = amex.test(card);
if(amexTest == true) {
expTest = expd.test(exDate);
if(expTest == true) {
document.getElementById('result').innerHTML = 'Congratulations! Your card is valid in terms of format.';
}
else {
document.getElementById('result').innerHTML = 'Invalid Expiry Date.';
}
}
else {
document.getElementById('result').innerHTML = 'Invalid Card Number';
}
break;
case 'Visa':
case 'VISA':
var visaTest = visa.test(card);
if(visaTest == true) {
expTest = expd.test(exDate);
if(expTest == true) {
document.getElementById('result').innerHTML = 'Congratulations! Your card is valid in terms of format.';
}
else {
document.getElementById('result').innerHTML = 'Invalid Expiry Date.';
}
}
else {
document.getElementById('result').innerHTML = 'Invalid Card Number';
}
break;
case 'MasterCard':
case 'MC':
var mcTest = mc.test(card);
if(mcTest == true) {
expTest = expd.test(exDate);
if(expTest == true) {
document.getElementById('result').innerHTML = 'Congratulations! Your card is valid in terms of format.';
}
else {
document.getElementById('result').innerHTML = 'Invalid Expiry Date.';
}
}
else {
document.getElementById('result').innerHTML = 'Invalid Card Number';
}
break;
case 'JCB':
var jcbTest = jcb.test(card);
if(jcbTest == true) {
expTest = expd.test(exDate);
if(expTest == true) {
document.getElementById('result').innerHTML = 'Congratulations! Your card is valid in terms of format.';
}
else {
document.getElementById('result').innerHTML = 'Invalid Expiry Date.';
}
}
else {
document.getElementById('result').innerHTML = 'Invalid Card Number';
}
break;
default:
document.getElementById('result').innerHTML = 'Invalid Card Type';
}
}
</script>
<p><b>Credit Card Format Checker</b></p><br>
<p id="name"></p>
<p id="cardType"></p>
<p id="cardNum"></p>
<p id="exDate"></p><br>
<p id="result"></p>
</div>
</div>
<div class="footer">
<h5><?php echo '© ', date('Y'), ' ', "WebDevScrims", ' :: Rundate ', date('m/d/Y'); ?></h5>
</div>
</body>
</html>