msiva1989 msiva1989 - 11 days ago 7
Javascript Question

Non Width Special Character Removal

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

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

<INPUT TYPE=TEXT NAME=MODEL VALUE="">
<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE="Next">

</FORM>
</BODY>
</HTML>


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,
"&#8203;&#8203;PMUE4526AAAAAA"
it's showing like that. so, my Java script program considers
"&#8203;"
(7 characters), not a special character.

Please help me to fix the problem.

kj_ kj_
Answer

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