Regular Expression To Match A Number Between 1 And 100

Have you ever wanted to validate a field that accepts numeric input of only numbers between 1 and 100? It can be trickier than you think without regular expressions.

Let me show a short yet useful regular expression that matches a number between 1 and 100.

/^([1-9][0-9]?|100)$/

Matches:

  • 1
  • 50
  • 100

Non-matches:

  • 0
  • 001
  • 101

Between 0 And 100

If you’re looking for a Regex to match a number between 0 and 100, try this instead:

/^(0|[1-9][0-9]?|100)$/

Matches:

  • 0
  • 1
  • 100

Non-matches:

  • -1
  • 001
  • 101

See Also: