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

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -