Gülay Uygun
Gülay Uygun

Reputation: 61

how to use uppercase method with do not allowed turkish character?

I have the following code:

<input type="text" style="text-transform: uppercase" />

The string gets transformed to uppercase, but ü for example, will transform to Ü.
I want ü to transform to U, e.g. Gülay should become GULAY.
Does anyone have any idea how can I do this?

Upvotes: 0

Views: 1775

Answers (2)

Metin &#214;zkan
Metin &#214;zkan

Reputation: 73

String.prototype.turkishToLower = function () {
var string = this;
var letters = {
  İ: "i", I: "i", ı: "i", Ş: "s", ş: "s", Ğ: "g", ğ: "g", Ü: "u", ü: "u", Ö: "o", ö: "o", Ç: "c", ç: "c",
};
string = string.replace(/(([İIıŞşĞğÜüÇçÖö]))/g, function (letter) {
  return letters[letter];
});
return string.toLowerCase();}


String.prototype.turkishToUpper = function(){
var string = this;
var letters = { "i": "I", "ş": "S", "ğ": "G", "ü": "U", "ö": "O", "ç": "C", "ı": "I" };
string = string.replace(/(([iışğüçö]))/g, function(letter){ return letters[letter]; });
return string.toUpperCase();}

use it "string".turkishToLower()

Upvotes: 2

rodrigogq
rodrigogq

Reputation: 1953

If this data is comming from a database, I suggest you treat this on your server before you send to your view. But you can also use a javascript for that if you don't want this to happen on the server.

Check out this answer: Remove accents/diacritics in a string in JavaScript

You could use something like:

var finalString = removeDiacritics(initialString).toUpperCase();

Upvotes: 1

Related Questions