Skip to content

Instantly share code, notes, and snippets.

@jgraffin
Forked from iruslani/remove-dash-example.js
Created June 24, 2019 12:52
Show Gist options
  • Save jgraffin/0ea14c40003caff2697efabc16f55bf5 to your computer and use it in GitHub Desktop.
Save jgraffin/0ea14c40003caff2697efabc16f55bf5 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