First, the second part of your comparable group is optional, so should you delete ?.
Secondly, since you only care about what appears at the beginning, there is no need to check the entire line up to $.
Finally, to return the empty string true, you also need to check for / ^ $ /.
What turns out:
/^(\+1|[^+]|$)/
For instance:
/^(\+1|[^+]|$)/.test(""); // true /^(\+1|[^+]|$)/.test("abc"); // true /^(\+1|[^+]|$)/.test("+1"); // true /^(\+1|[^+]|$)/.test("+1abc"); // true /^(\+1|[^+]|$)/.test("+2"); // false /^(\+1|[^+]|$)/.test("+abc"); // false
(console should be open)
source share