i need a regular expression to validate only allow -1 and all other positive integers.any other negative value other than -1 is not allowed.
i’ve the following which only allow integers but need to allow -1 as well.plz help
^\d+$
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
^(-1|[1-9]\d*)$?The reason for the
[1-9]\d*is to not allow 0 (because you said “positive integers”).If you want to allow 0 just do
^(-1|\d+)$.