Masoud Tavakkoli
Masoud Tavakkoli

Reputation: 1020

convert all type of languages to one for comparison

I have a search text input, I use this script for search, the function I use for standardize string is str.toLowerCase. It 's worked perfectly for English statement. but in my case there is other languages like Arabic and Persian.

In this situation my search function does not work correct. How can I Convert all string to one type of something that I can use it for compare strings.

search function:

$(document).ready(function(){
    $('#myInput').on('keyup', function () {

        var valThis = $(this).val().toLowerCase(); //<--------------

        $('#areas_list>option').each(function(){

            var text = $(this).text().toLowerCase(); // <---------

            for (var i = 0; i < text.length; i++) {
                if (text.search(valThis) > 0) {
                    $(this).show();
                }else if (!valThis) {
                    $(this).show();
                }else {
                    $(this).hide();
                }
            }
        });
    });
});

Upvotes: 0

Views: 122

Answers (1)

gurvinder372
gurvinder372

Reputation: 68433

I use this script for search, the function I use for standardize string is str.toLowerCase. It 's worked perfectly for English statement. but in my case there is other languages like Arabic and Persian.

You can use toLocaleLowerCase

var valThis = $(this).val().toLocaleLowerCase();

As per doc

The default locale is the host environment’s current locale.

Please note that

  • You need to pass the locale if your system's locale is not the locale of the data.

Upvotes: 1

Related Questions