allowedChars
function, since version 1.0.0
categories: sanitizing, strings
allowedChars(str, regex, replacement)
This functions replaces every character in input not mathing regex expression with replacement string. Used this function to sanitize data.
parameters
- str: string - input string to modify
- regex: string - matching regex
- replacement: string - string that will replace text not matched by regex
return type:
string
examples
allowedChars('Hello123!@The-re#', 'a-zA-Z', '')
allowedChars('Hello123~@The-re#', 'a-zA-Z0-9', '-')
returns
HelloThere
Hello123--The-re-