regex allow only numbers or empty string

Viewed 84254

Can someone help me create this regex. I need it to check to see if the string is either entirely whitespace(empty) or if it only contains positive whole numbers. If anything else it fails. This is what I have so far.

/^\s*|[0-9][0-9]*/
6 Answers

This helped me. It matches empty string and any number you enter.

/^(|\d)+$/

Try here if you want: regex101.com

Related