javascript - Filtering out 0-9 & dashes only? -
i create regexp targets characters in string isn't 0-9 (numeric) or - (dash). wrong below regexp?
regex:
regex = '/^[0-9-]/g'; js implementation:
$(this).val($(this).val().replace(regex, ''));
i think meant ^ inside character class. also, regexes not strings:
regex = /[^0-9-]/g; $(this).val($(this).val().replace(regex, ''));
Comments
Post a Comment