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

1 Answer 1

2

/^[0-9]*$/ allows any amount of digits, including none at all (= empty string).

In case you want to keep whitespace allowed, use /^[0-9 ]*$/ (no need to escape the space character).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.