开发者

RegExp check if it's a number while it's not empty

开发者 https://www.devze.com 2023-03-20 13:06 出处:网络
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:

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号