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

Popular posts from this blog

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

java - Why is BlockingQueue.take() not releasing the thread? -

jQuery Ajax Render Fragments OR Whole Page -