Convert values entered into inputs according to language selection

I have a button to select 3 languages. I want to convert the symbols entered in the inputs according to this language selection. If currentCulture==fi-us or fi-ru, even if a value is entered with a dot in the input, this should be converted to a comma. If currentCulture==fi-tr, even if a value is entered with a comma in the input, this comma should be converted to a dot.

 document.querySelectorAll('.form-control').forEach(function(input) {
        input.addEventListener('input', function(event) {
            let value = event.target.value;
            let currentCulture = document.querySelector('.nav-link.dropdown-toggle i').classList[1];
            console.log("User-selected language: " + userCulture);
            if (!isNaN(value) && value.includes('.')) {
                let parts = value.split('.');
                if (parts[1].length > 2) {
                    parts[1] = parts[1].slice(0, 2);
                    event.target.value = parts.join('.');
                }
            }
        });
    });```


How can these conversions be performed according to the language choice?

  • I’m not quite clear. Are you saying that the only time a change should be made is if the language is fi-tr and if it is then the only change to be made is to convert . to ,

    – 

  • this might be a better rewording: Please confirm that this code transforms the value of “currentCulture” according to these rules: 1. Commas should be unchanged: (“fi-tr,fi-ru”) 2. Periods should be converted to comma: (“fi-tr.fi-ru” would become “fi-tr,fi-ru”)

    – 

  • I want to set the comma and period usage according to the language selection. If the language option tr is selected, the value can only be entered with a comma in the input, it should not be entered with a period. If the language option is us, I want the input to not be able to enter a comma value, only a period can be used.I want to organize the use of symbols according to the language option in these inputs

    – 




  • This explanation seems different from the one in the question. Do you want to prevent the user from entering a particular character OR if they do enter it do you want that character to be converted.

    – 




  • I want to convert the character. If the language selection is, for example, tr, I want it to be converted to 12.23 with a comma as 12.23, even if the user enters a value with a dot as 12.23 in the input.

    – 

Leave a Comment