Skip to content

Commit f032d63

Browse files
committed
Edited input validation to prevent decimal values (e.g., 12.5 pages). prevent extremely large numbers of pages (e.g., 9999999). checks if author/title length is within reasonable range.
1 parent b77a783 commit f032d63

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

debugging/book-library/script.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ window.onload = function () {
3838
alert("Please fill all fields with valid values (no empty spaces, pages must be a positive number).");
3939
return;
4040
}
41+
if (!title || title.length < 2) {
42+
alert("Title must be at least 2 characters long.");
43+
return;
44+
}
45+
if (!author || author.length < 2) {
46+
alert("Author must be at least 2 characters long.");
47+
return;
48+
}
49+
const pageNum = Number(pages);
50+
if (!Number.isInteger(pageNum) || pageNum <= 0 || pageNum > 10000) {
51+
alert("Pages must be a positive whole number (1–10,000).");
52+
return;
53+
}
4154

4255
// Add book
4356
let book = new Book(title, author, pages, read);

0 commit comments

Comments
 (0)