-
-
Save brunocoelho/564b54f37d6f3928c380351dd2df44e0 to your computer and use it in GitHub Desktop.
JavaScript Regular Expression Whitelist for String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in the regex, the carrot(^) negates the match, so if the stringToReplace contains something that is not a-z or 0-9 it will be replaced | |
// In this case the desired string will only be alpha numeric characters, stripping out spaces and symbols | |
// Help from: http://stackoverflow.com/questions/4374822/javascript-regexp-remove-all-special-characters | |
var desired = stringToReplace.replace(/[^a-zA-Z0-9]/gi, '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment