-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript1.js
More file actions
74 lines (65 loc) · 2.39 KB
/
script1.js
File metadata and controls
74 lines (65 loc) · 2.39 KB
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
const form = document.querySelector('form');
const datetimeElement = document.getElementById('datetime');
const confirmCheckbox = document.getElementById('confirm');
const mobileNumberInput = document.getElementById('Mobile_no');
const pincodeInput = document.getElementById('Pincode');
function updateDateTime() {
const now = new Date();
const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
let month = monthNames[now.getMonth()] ;
let day = dayNames[now.getDay()];
month=month<10? '0'+month:month;
let date = now.getDate();
date=date<10? '0'+date:date;
const year = now.getFullYear();
let hours = now.getHours();
let minutes = now.getMinutes();
let sec=now.getSeconds();
const ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds=sec<=9? '0'+sec:sec;
const dateTimeString = day+', '+month+'/'+date+'/'+year+', '+hours+':'+minutes+':'+seconds+' '+ampm;
datetimeElement.innerText = dateTimeString;
}
updateDateTime();
setInterval(updateDateTime, 1000);
function isNumeric(value) {
var flag=1
for (i=0;i<value.length;i++){
if(value[i]<'0'|| value[i]>'9' ){
flag=0;
break
}
}
return flag;
}
form.addEventListener('submit', (event) => {
let isValid = true;
if (!confirmCheckbox.checked) {
alert('Please confirm the information is accurate and agree to the event terms and waiver.');
isValid = false;
}
if (!isNumeric(mobileNumberInput.value)) {
alert('Mobile Number must contain only digits.');
isValid = false;
} else if (mobileNumberInput.value.length !== 10) {
alert('Mobile Number must contain exactly 10 digits.');
isValid = false;
}
if (pincodeInput.value !== '') {
if (!isNumeric(pincodeInput.value)) {
alert('Pincode must contain only digits.');
isValid = false;
} else if (pincodeInput.value.length !== 6) {
alert('Pincode must contain exactly 6 digits.');
isValid = false;
}
}
if (!isValid) {
event.preventDefault();
} else {
alert('Form submitted successfully!');
}
});