Check if a string is an integer in javascript

Small function in pure Javascript to check if a string is an integer or not.

function isInteger(value) {
    var intRegex = /^\d+$/;
    return intRegex.test(value);
}

isInteger(5);         // true
isInteger(undefined); // false
isInteger("1");       // true
isInteger("1.3");     // false
isInteger(".Maui")    // false

Leave a Comment

Your email address will not be published. Required fields are marked *