I want JavaScript functions that will work just like escape() but I want all non-whitelisted charachters to be encoded.
These charachters should be whitelisted:
bcdefghijklmnopqrstuvwxyzB
CDEFGHIJKL
MNOPQRSTUV
WXYZ012345
6789_
Because the letter "A" is not whitelisted, it should be URL encoded.
For example:
A test, 123-456
Should become:
%41%20test%2C%20123%2D456%
20
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Demo</title>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
var x = 'A test, 123-456';
alert(escapeNonWhitelisted(x));
function escapeNonWhitelisted(str) {
return escape(str);
}
//]]>
</script>
</body>
</html>
Open in new window