msiva1989 msiva1989 - 1 year ago 77
Javascript Question

Non Width Special Character Removal

Below is my HTML Code to get the input from User.

<FORM METHOD=POST onSubmit="javascript:return(exa(this.form.model.value))">



When User entered the Model name (Having zero width special characters) --> ​​PMUE4526AAAAAA

Below is the java script to remove the non-ascii characters. but, it's not working for me.

function exa(myString)
alert("String: "+myString);alert("String_length: "+myString.length);
myString= myString.replace(/[^\x20-\x7e]/g,'');
alert("String: "+myString);alert("String_length: "+myString.length);

Whenever i am trying to display the value which i received from HTML,
it's showing like that. so, my Java script program considers
(7 characters), not a special character.

Please help me to fix the problem.

kj_ kj_
Answer Source

Try with this regex in the replace: /([^\x00-\x7F]|&#[0-9]+;)/g

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download