Skip to content

Instantly share code, notes, and snippets.

@iruslani
Created May 9, 2012 23:54
Show Gist options
  • Save iruslani/2649892 to your computer and use it in GitHub Desktop.
Save iruslani/2649892 to your computer and use it in GitHub Desktop.
JS Function to remove dashes. You can use it for other characters as well by changing the js regular expression.
<script type="text/javascript">
$(document).ready(function(){
$.cleanString = function(testString) {
var numericString = testString.replace(/-/gi," ");
// .replace() uses regular expression. In this case, its replaceing '-' with ' '.
return numericString;
}
var question = "Sample-text-with-some-dashes";
var cleaned = $.cleanString(question);
alert(cleaned);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment