<input type="txt" id="give_lang"></br> <button onclick='lngtype()'>Language</button> <div id="lang_her">0</div> <script type="text/javascript"> function lngtype(text) { var text = document.getElementById("give_lang").value.replace(/\s/g); //read input value, and remove "space" by replace \s //Dictionary for Unicode range of the languages var langdic = { "arabic" : /[\u0600-\u06FF]/, "persian" : /[\u0750-\u077F]/, "Hebrew" : /[\u0590-\u05FF]/, "Syriac" : /[\u0700-\u074F]/, "Bengali" : /[\u0980-\u09FF]/, "Ethiopic" : /[\u1200-\u137F]/, "Greek and Coptic" : /[\u0370-\u03FF]/, "Georgian" : /[\u10A0-\u10FF]/, "Thai" : /[\u0E00-\u0E7F]/, "english" : /^[a-zA-Z]+$/ //add other languages her } //const keys = Object.keys(langdic); //read keys //const keys = Object.values(langdic); //read values const keys = Object.entries(langdic); // read keys and values from the dictionary Object.entries(langdic).forEach(([key, value]) => { // loop to read all the dictionary items if not true if (value.test(text) == true){ //Check Unicode to see which one is true return document.getElementById("lang_her").innerHTML = key; //print language name if unicode true } }); } </script>
source share