Regex: Check for valid integer
30 July 2023 (Updated 30 July 2023)
On this page
General pattern
/^-?\d+$/
JavaScript example
function isValidInteger(value) {
return /^-?\d+$/.test(value)
}
// isValidInteger(50) // true
// isValidInteger(-30) // true
// isValidInteger(--10) // false
// isValidInteger (-6-10) // false
Tagged:
Regex
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment