Regex to check whether a string contains only numbers [duplicate]

var reg = /^\d+$/;

should do it. The original matches anything that consists of exactly one digit.

Leave a Comment