Number range regex

am using the below regex to make sure input is good

A whole number between 1 and 99

/^\d{[1-99]$/

in this function, but its not working

if( !value.match(/^\d{[1-99]$/)) {
	document.getElementById("Quantity_Error").innerHTML = "Must be a whole number from 1 to 99";
	document.getElementById("Quantity").focus();
} else {
	document.getElementById("Quantity_Error").innerHTML = "";
}

Do you see the error?

Oh… my mistake

/[1]$|[2]\d$/


  1. 1-9 ↩︎

  2. 1-9 ↩︎

2 Likes

I think you can simplify it down to
^[1-9]\d?$

Results at (remove the modifiers g and m for actual use)

2 Likes

Yes, I thought of that just after shutting the computer down


  1. 1-9 ↩︎

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.