Alex Rivera | Logout

How to remove periods in a string using jQuery

Asked 2010-10-16T16:47:47.957
9

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?

Edit
Report

2 Answers

17

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

Use the global modifier:

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

replace() at MDC

answered 2010-10-16T16:51:05.260
2

The method used to replace the string is not recursive, meaning once it found a matching char or string, it stop looking. U should use a regular expression replace.

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

Check out Javascript replace tutorial for more info.

answered 2010-10-16T16:56:30.133

Your Answer