10 examples of 'javascript check if string is integer' in JavaScript

Every line of 'javascript check if string is integer' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
383function integer(value) {
384 return /^(?:[-+]?(?:0|[1-9][0-9]*))$/.test(value);
385}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

72, Integer : function _fnValidInteger(obj) {
73 var elValue = $(obj).val();
74 var isValid = ( (elValue.length===0) || (/^-?\d+$/.test(elValue)) );
75 return isValid;
76 //return spa['_validate']._showValidateMsg(obj, msg, isValid);
77 }
216function isInteger(str) {
217 var c0 = str.charCodeAt(0);
218 if (c0 >= 48 && c0 <= 57) return !/\D/.test(str);
219 else return false;
220}
46export function integer(value) {
47 if (!Number.isInteger(Number(value))) {
48 return 'Must be an integer'
49 }
50 return undefined
51}
163integer(value)
164{
165 return (/^(-?[1-9]\d*|0)$/).test(value);
166}
62function isInt(value) {
63 return Math.floor(value)== value;
64}
249function isValidInteger (value) {
250 return /^[+-]?\d+$/.test(value);
251}
171function isPositiveInteger(s) {
172 var re = /^[0-9]+$/;
173 return re.test(s)
174}
97function isInteger (value) {
98 logger(`isInteger`, value)
99 return isNumber(value) && !isNan(value) && value % 1 === 0
100}
62function isNumber(value) {
63 var patrn = /^(-)?\d+(\.\d+)?$/;
64 if (patrn.exec(value) == null || value == "") {
65 return false
66 } else {
67 return true
68 }
69}

Related snippets