Validate that a string is a positive integer

I would like the simplest fail-safe test to check that a string in JavaScript is a positive integer.

isNaN(str) returns true for all sorts of non-integer values and parseInt(str) is returning integers for float strings, like “2.5”. And I don’t want to have to use some jQuery plugin either.

15 Answers
15

Leave a Comment