JAVASCRIPT string with Cyrillic

JAVASCRIPT string with Cyrillic

Problem: when entering text in a text field ( "Title") you want to display its value in another transliterovannoe ( "UserKey"), while in transliteration allowed only letters, numbers and dashes.

Sample HTML with two fields:

To enable transliteration add the following javascript-code on the page:

1234567891011121314151617 function toTranslit(text) {return text.replace(/([а-яё])|([\\s_-])|([^a-z\\d])/gi,function (all, ch, space, words, i) {if (space || words) {return space ? '-' : '';}var code = ch.charCodeAt(0),index = code == 1025 || code == 1105 ? 0 :code > 1071 ? code - 1071 : code - 1039,t = ['yo', 'a', 'b', 'v', 'g', 'd', 'e', 'zh','z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p','r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh','shch', '', 'y', '', 'e', 'yu', 'ya']; return t[index];});}

This code adds a new method "translit" to a string variable. Now we can use it in the code text fields:

When you enter values ​​in the Title, will be automatically filled UserKey field.

An example of the implementation of the script on the ASP page:

123456789101112131415161718192021222324252627282930 <script type="text/javascript">function toTranslit(text) {return text.replace(/([а-яё])|([\\s_-])|([^a-z\\d])/gi,function (all, ch, space, words, i) {if (space || words) {return space ? '-' : '';}var code = ch.charCodeAt(0),index = code == 1025 || code == 1105 ? 0 :code > 1071 ? code - 1071 : code - 1039,t = ['yo', 'a', 'b', 'v', 'g', 'd', 'e', 'zh','z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p','r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh','shch', '', 'y', '', 'e', 'yu', 'ya']; return t[index];});}function SetTranslit(val) {document.getElementById('<%= tbxNewsURLKey.ClientID %>').value = toTranslit(val);}script><p>Заголовок:<asp:TextBox ID="tbxTitle" runat="server" onkeyup="SetTranslit(this.value)">asp:TextBox><p>URL name:<asp:TextBox ID="tbxNewsURLKey" runat="server">asp:TextBox>

Read in other languages

 BelorussianEnglish Deutsch Spanish French Italian Portuguese Turkish Arab Ukrainian Swedish Hungarian Bulgarian Estonian Chinese (Simplified) Vietnamese Romanian Thai Slovenian Slovak Serbian Malay Norwegian Latvian Lithuanian Korean Japanese Indonesian Hindi Hebrew Finnish Greek Dutch Czech Danish Croatian Chinese (Traditional) Philippine Urdu Azeybardzhansky ArmenianPolish Bengal Georgian Kazakh Catalan Mongolski Russian Tadzhitsky Tamilʹskij telugu Uzbetsky

Read more:   speed up the loading DESKTOP WINDOWS XP

Add a comment

Your e-mail will not be published. Required fields are marked *