Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove periods in a string using jQuery

I have the string R.E.M. and I need to make it REM

So far, I have:

$('#request_artist').val().replace(".", "");

...but I get RE.M.

Any ideas?

like image 880
Matt Elhotiby Avatar asked Oct 16 '10 16:10

Matt Elhotiby


2 Answers

The first argument to replace() is usually a regular expression.

Use the global modifier:

$('#request_artist').val().replace(/\./g, "");

replace() at MDC

like image 78
Pekka Avatar answered Oct 12 '22 23:10

Pekka


You could pass a regular expression to the replace method and indicate that it should replace all occurrences like this: $('#request_artist').val().replace(/\./g, '');

like image 41
Darin Dimitrov Avatar answered Oct 12 '22 22:10

Darin Dimitrov