hi I found on the Internet that this regexp accept positive number ^\d+$ and this accept nothing ^$
So no I wanna combine this two regexp but with no success. I try this (^\d+$)|(^$) but this didnt work. So help me with regexp which accept positive integer and nothing
thx a lot
hi I found on the Internet that this regexp accept positive number ^\d+$ and
Share
Simply do:
The
*means: “zero or more times”.Since you’ve asked most questions with the Java tag, I’m assuming you’re looking for a Java solution. Note that inside a string literal, the
\needs to be escaped!A demo:
produces:
Note that
matches(...)already validates the entire input string, so there’s no need to “anchor” it with^and$.Beware that it would also return true for numbers that exceed
Integer.MAX_VALUEandLong.MAX_VALUE. SO even ifmatches(...)returned true,parseInt(...)orparseLong(...)may throw an exception!