Please can you help me, I need a regex expressions to only allow whole numbers and the string cannot be blank.
Thanks
/^-?\d+$/
This regex would match one or more digits. So won't allow blank as required, and would only allow whole numbers
Actually the +
after \d
imposes that at least one digit be present in the input string.
The -
in the beginning checks for a -
, and the following ?
makes it optional.
You should try this one:
^\d+$
^ : begining of the string to capture
$ : end of the string to capture
\d : all the digits (equivalent to [0-9])
+ : at least one of the class