-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataval.js
More file actions
67 lines (53 loc) · 1.99 KB
/
dataval.js
File metadata and controls
67 lines (53 loc) · 1.99 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
// data-validation.js
// Function to validate the entire table
function validateTable() {
console.log("Validation started");
// Clear previous errors
let isValid = true;
const rows = document.querySelectorAll("#syllabus-data tr");
const lastRow = rows[rows.length - 1]; // Get the last added row
const cells = lastRow.querySelectorAll("td");
const title = cells[1].textContent.trim();
const topics = cells[2].textContent.trim();
const lectures = cells[3].textContent.trim();
// Validate Title (should not be empty)
if (!isValidString(title)) {
alert("Title must not be empty.");
isValid = false;
}
// Validate Topics (should not be empty)
if (!isValidString(topics)) {
alert("Topics must not be empty.");
isValid = false;
}
// Validate Lectures (should be an integer and greater than 0)
if (!isValidLectures(lectures)) {
alert("Lectures must be a positive integer.");
isValid = false;
}
console.log("Validation completed, isValid:", isValid);
return isValid;
}
// Function to validate if a value is a positive integer
function isValidModuleNo(value, index) {
if (!value.match(/^\d+$/)) {
return false;
}
if (index > 0) {
const prevModuleNo = parseInt(document.querySelectorAll("#syllabus-data tr")[index - 2].querySelector("td").textContent.trim());
if (parseInt(value) <= prevModuleNo) {
alert("Module no should be greater than the previous.");
return false;
}
}
return true;
}
// Function to validate if a value is a non-empty string
function isValidString(value) {
return value !== "";
}
// Function to validate if lectures is a positive integer
function isValidLectures(value) {
const intValue = parseInt(value);
return !isNaN(intValue) && intValue > 0;
}