Last active
October 15, 2022 18:59
-
-
Save steveosoule/4495982 to your computer and use it in GitHub Desktop.
JavaScript Regular Expression Whitelist for String
This file contains hidden or 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, '') |
Thank you!
It's "caret" btw :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A real hero!