RegExp check if it's a number while it's not empty
I'm using开发者_如何学运维 vbulletin and I can set to custom fields regexp.
I've created a custom field that are userids and only accepts numbers, so the regexp I'm using is:
\d+
But I need to allow it to be empty. Any ideas?
Thanks
\d*
where * indicates 0 or more digits
Then use this:
\d*
This means zero or more digits. Zero digits naturally means it is empty.
Assuming your framework wraps it with the appropriate anchors, just transform that to
\d*
which matches any number of digits, including 0 digits.
/^\d*$/
would be better if nothing is anchoring that for you.
Change this plus (1 or more) to a star (0 or more).
精彩评论