Regex to check whether a string contains only numbers [duplicate] September 21, 2022 by Tarik var reg = /^\d+$/; should do it. The original matches anything that consists of exactly one digit.