Special Characters
! @ # $ % ^ & * ( ) _ + = - { [ } ] : ; " ' | \\ < , > . ? /
I have a simple saving of data. I notice that if I enter all special characters in a textbox and not using a escape
method all special character after the &
sign is being cut.
With Out Escpae
Output
! @ # $ % ^
With Escape
JS
var txt = $("txtbox").val();
Notice that the output has a %20%
how I remove it?.
%20
is space. If you wish to remove it, you can do it like,
Note that escape
is deprecated, Use encodeURIComponent
instead.
var str = `! @ # $ % ^ & * ( ) _ + = - { [ } ] : ; " ' | \ < , > . ? /`;
var encoded = encodeURIComponent(str.split(' ').join(''));
// or encodeURIComponent(str.replace(/\s+/g, ''));
alert(encoded);
And here's your fiddle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.