Skip to content

Commit 52b6bac

Browse files
Merge pull request steam-bell-92#1532 from mayurigade-hub/fix/armstrong-decimal-validation
fix: reject decimal input in Armstrong number checker
2 parents 4c04e31 + 881ae39 commit 52b6bac

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

web-app/js/projects/armstrong.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,18 @@ function initArmstrong() {
171171
return;
172172
}
173173

174-
const num = parseInt(numStr);
174+
// Strict whole-number validation: only digits allowed (no decimals,
175+
// letters, symbols, signs, or scientific notation). This rejects
176+
// things like "153.9", "12e3", "-5", "abc" before parseInt ever
177+
// gets a chance to silently truncate them.
178+
const isWholeNumber = /^\d+$/.test(numStr);
179+
180+
if (!isWholeNumber) {
181+
resultDiv.innerHTML = '<div class="armstrong-result"><p style="color: #f44336;">⚠️ Please enter a valid positive whole number (no decimals, letters, or symbols)!</p></div>';
182+
return;
183+
}
184+
185+
const num = parseInt(numStr, 10);
175186

176187
if (isNaN(num) || num < 0) {
177188
resultDiv.innerHTML = '<div class="armstrong-result"><p style="color: #f44336;">⚠️ Please enter a valid positive integer!</p></div>';

0 commit comments

Comments
 (0)