1

I am having this issue where I want an INPUT field to be just NUMBERS or EMPTY. If a user chooses to add a phone number or leave it blank if they don't want to.

I tried using this, but it requires a phone number if it's empty:

 "onlyNumberSp": {
                "regex": /^[0-9\ ]+$/,
                "alertText": "* Numbers only"
            },

Thank you

4

1 回答 1

2

/^[0-9]*$/允许任意数量的数字,包括一个都没有(= 空字符串)。

如果您想保留空格,请使用/^[0-9 ]*$/(无需转义空格字符)。

于 2012-11-15T15:32:40.563 回答