For ranges, a hyphen in the [] block is used. Therefore, the% to% value is invalid. You can avoid this:
var pattern = new RegExp(/[_\-%]/);
or go to the beginning:
var pattern = new RegExp(/[-_%]/);
or to the end:
var pattern = new RegExp(/[_%-]/);
Since the regular expression knows that a hyphen at the beginning (or end, thanks BrunoLM!) Means a literal hyphen, not a range.
WSkid source
share