Linked Questions

1 vote
3 answers
8k views

function isNumber(n) { var j = n.trim(); return (j % 1 === 0 && j != ""); } My function still returns true if the inputted value is "14.0". It should only allow whole numbers without any ...
mengmeng's user avatar
  • 1,506
4 votes
1 answer
4k views

I am scratching my head to find numbers like 10.0 , 1.0 are whether integers or floats. is there any way to check whether 10.0 is float or int in javascript ?? Thanks
REDDY PRASAD's user avatar
  • 1,409
-1 votes
2 answers
488 views

I have a recursion function which calculates factorial for a given number. function findFactorial(num) { if (num < 1 || !num.isInteger) { return "error"; } else { return num * ...
Ati's user avatar
  • 304
0 votes
1 answer
191 views

how do I write a defensive line of code stating a parameter must be a number or else console.log 'it must be a number function getDiscount(taxBoolean,guests) { getPrices(taxBoolean) let ...
Ighodan's user avatar
0 votes
2 answers
92 views

I need to validate whether a input is a valid integer allowing for +/- entries. I have tried this. function valid(elem) { var num = parseInt(elem); if(!Number.isInteger(num)) { ...
AriiNkhun's user avatar
-2 votes
1 answer
78 views

I have a stripe bank account verification form that requires integers in a certain format. No decimals, no letters etc. When the user inputs something incorrectly and submits, the page turns into ...
Daniel Taylor's user avatar
0 votes
0 answers
20 views

const sumAll = function(x, y) { let sum = 0; if (x < 0 || y< 0 || isNaN(x) || isNaN(y) || Number(x) !== x || Number(y) !== y ) { return "ERROR"; } else { if (x > y) { ...
transcenddev's user avatar
1127 votes
79 answers
2.9m views

Is there a quick way to set an HTML text input (<input type=text />) to only allow numeric keystrokes (plus '.')?
94 votes
11 answers
477k views

I'm using forms in HTML and javascript. I would like an alert to pop up only if the user inputs a LETTER and clicks submit. So I have the HTML code: <form name="myForm" action="" onsubmit="return ...
Greg Peckory's user avatar
  • 8,138
30 votes
7 answers
21k views

How can I test a variable to ascertain if it contains a number, and it is an integer? e.g. if (1.589 == integer) // false if (2 == integer) // true Any clues?
user avatar
2 votes
3 answers
19k views

I'm starting to learn JavaScript at school and one of the assignments require me to check user's input whether it is an Integer or not. This code DOES NOT WORK FOR ME ON CHROME. var person = ...
user3072143's user avatar
6 votes
6 answers
11k views

Is it good to use +prompt instead of just regular prompt in JavaScript if I want only integer numbers to be typed in my prompt window? Does it say something like that about +prompt in the JavaScript ...
Newcomer's user avatar
  • 503
2 votes
7 answers
489 views

This sounds easy but unable to get it to work. I need to accept a percentage number from 0 to 100 with no decimal numbers, no negative numbers. How can I do this validatation? if ((Pcomplete == "" ) ...
Baba's user avatar
  • 2,247
-4 votes
5 answers
5k views

when user clicks the button I want to check if user entered an integer value in the box above. If false show alert message, if true go to next page. What am I missing, it seems so simple... <html&...
Rajesh Muntari's user avatar
-2 votes
1 answer
3k views

I've been looking all over (various forums and tutorials, etc.) and trying to find something that can work. Couple of things first: • I'm very new to javascript (and all languages really), but ...
Steven L's user avatar

15 30 50 per page