So you need to replace all the occurrences of a character in a javascript variable… Well that’s not too hard.
I’ll put the code into a function that you can call from anywhere in javascript.
I decided to use a regular expression in the replace syntax… No real reason though. But it works. The idea here is that you call the function, the string you want to check is passed through the regular expression and all the commas are replaced by an “_” (or any other character you choose).
<script type="text/javascript">
function removeComma(field) {
field = field.replace(/,/g,"_");
return field;
}
</script>
removeComma('this is the, string, I want to check, for commas');
Result: “this is the_ string_ I want to check_ for commas”.
This entry was written by Blaine Linehan
closeAuthor: Blaine Linehan
Name: Blaine Linehan
Email: blaine.linehan@wichita.edu
Site: http://blaineblog.apcapart.com/
About: I was born in Maine, and I’ll be a Maniac til I die. I’ve lived in several states, been in several countries, and lived outside the US so far (I’m not thirty yet). Right now I live in Kansas with my wife, Jana, and our four month old daughter, Bailey. I have a degree in Information Systems Technology from Penn State University and another degree in Computer Information Systems from Central Pennsylvania College. I started as a history major at the University of Central Florida but found that very very boring. So now I’m working at the Wichita State University here in Kansas doing what I love to do – expanding my computer horizons and deciding which of my 5 monitors I should work on next.See Authors Posts (11) and posted on 2009-09-16 @ 16:22:14-0400 and filed under Code, JS. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
Leave a Reply