Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex in javascript with latin and turkish characters

I am trying to replace all the non latin/turkish characters, but something is wrong and I can't find it.

For example:

var texto = '*istediğiniz*';
if (texto.match(/[^a-zA-Z0-9şŞıİçÇöÖüÜĞğ\- ]/g)){

    //only letters, numbers and turkish letters are allowed
    texto = texto.replace(/[^a-zA-Z0-9şŞıİçÇöÖüÜĞğ\- ]/g, ''); 
}

console.log(texto);

As a result, my word is output incorrectly: istediiniz. The output should be istediğiniz.

like image 246
manix Avatar asked Oct 21 '22 12:10

manix


1 Answers

Encode your javascript file into utf-8 and update your meta tag to:

<meta http-equiv="content-type" content="text/html;charset=utf-8" />
like image 105
carmina Avatar answered Oct 27 '22 22:10

carmina