You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: web-app/js/projects/armstrong.js
+12-1Lines changed: 12 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -171,7 +171,18 @@ function initArmstrong() {
171
171
return;
172
172
}
173
173
174
-
constnum=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
+
constisWholeNumber=/^\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
+
constnum=parseInt(numStr,10);
175
186
176
187
if(isNaN(num)||num<0){
177
188
resultDiv.innerHTML='<div class="armstrong-result"><p style="color: #f44336;">⚠️ Please enter a valid positive integer!</p></div>';
0 commit comments