Regex for Positive numbers and -1 Javascript

时间:2016-02-12 19:51:30

标签: javascript regex

I was trying to look for it, but couldn't find any ref , I'm looking for a regex that will accept all positive integers include -1 (only - no other negative numbers) .

My regex is now /^\d+$/ But this is only for the part of all positive integers .

What should i add to that regex to work out ?

Thanks !!!

1 个答案:

答案 0 :(得分:2)

Try: /^(-1|\d+)$/

See it working here: https://regex101.com/r/dG3xS3/1