Linked Questions
33 questions linked to/from How to check if a variable is an integer in JavaScript?
1
vote
3
answers
8k
views
Only allow whole numbers in input field [duplicate]
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 ...
4
votes
1
answer
4k
views
is it possible check whether `10.0` is float or int in javascript ?? [duplicate]
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
-1
votes
2
answers
488
views
Check if number is not integer in recursion js [duplicate]
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 * ...
0
votes
1
answer
191
views
how to define a parameter must be a number in a function [duplicate]
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 ...
0
votes
2
answers
92
views
How to validate whether a variable is valid integer allowing +/-? in pure javascript [duplicate]
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))
{
...
-2
votes
1
answer
78
views
PHP error handling while remaining on form page [duplicate]
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 ...
0
votes
0
answers
20
views
How do I return Error with non-integer parameters? [duplicate]
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) {
...
1127
votes
79
answers
2.9m
views
HTML text input allow only numeric input
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
Check if input is number or letter javascript
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 ...
30
votes
7
answers
21k
views
How to detect if a given number is an integer?
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?
2
votes
3
answers
19k
views
Checking if variable is an Integer in Javascript
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 = ...
6
votes
6
answers
11k
views
+prompt vs prompt in JavaScript
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 ...
2
votes
7
answers
489
views
Validating a percentage variable. No decimal points, No negative numbers
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 == "" ) ...
-4
votes
5
answers
5k
views
Check if user input is an integer (Javascript)
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&...
-2
votes
1
answer
3k
views
Javascript: do not display, if 0, null, or NaN
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 ...