How would I go about building a regex that allows only digits, with no spaces, and an optional “+” at the beginning?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
try this
^anchors it to the start of the string,$to the end\+?is the optional +\dis a digit and the following+is the quantifier that says at least one (digit).A useful resource to learn regular expressions is the tutorial of regular-expressions.info
And Regexr is a very useful resource to test regular expressions, see this regex here online