It needs to start with a ^ and the - needs to be escaped with a \
pattern=/^[0-9 \-+]+$/;
It needs to start with a ^ as that is an anchor for the start of the string, if you didn't it would validate strings that started with anything, as long as they ended with a number, space, - or +
-
needs to be escaped as it is a special character and has a meaning other than -
. While +
is a special character, and if you want to treat it as a +
outside a class it needs to be escaped, when inside a class only ]^-\
need to be escaped.
So outside of a class escape
.^$|*+?()[{\
And inside escape:
]^-\
However, most implementations allow you to escape all 12 special characters inside classes without error, and they will only give an error if you escape a non special character, which means that this (Note the extra \
before the plus) will also work fine.
pattern="^[0-9 \-\+]+$"
I always find that using a regex tester makes things easier as it allows me to see mistakes.