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

return type:

string

examples

allowedChars('Hello123!@The-re#', 'a-zA-Z', '')       
allowedChars('Hello123~@The-re#', 'a-zA-Z0-9', '-')

returns

HelloThere
Hello123--The-re-

Related functions:

Update your privacy settings