Last active
August 29, 2015 14:13
-
-
Save umanda/a2cae0553995b1d69c11 to your computer and use it in GitHub Desktop.
Sinhala and English text detector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Unicode detector</title> | |
<script> | |
function myFunction() { | |
var x = document.getElementById("frm1"); | |
var data = ""; | |
data = x.elements[0].value; | |
var result; | |
var en=0; | |
var si=0; | |
var other=0; | |
//checking ascii value of the characters. | |
for(var i=0;i<data.length;i++){ | |
var n = data.charCodeAt(i); | |
if(n>64 && n<123){ | |
en++; | |
} | |
else if(n>3455 && n<3584){ | |
si++; | |
} | |
else{ | |
other++; | |
} | |
} | |
if(en>0 && si==0 && other==0){ | |
//alert('English'); | |
result='English'; | |
} | |
else if(en==0 && si>0 && other==0){ | |
//alert('Sinhala'); | |
result='Sinhala'; | |
} | |
else { | |
//alert('Error'); | |
result='Error'; | |
} | |
document.getElementById("demo").innerHTML = result; | |
} | |
function myFunction2() { | |
document.getElementById("frm1").reset(); | |
} | |
</script> | |
</head> | |
<body> | |
<form id="frm1"> | |
add the word <input type="text" name="word" id="word"> | |
</form> | |
<button onclick="myFunction()">check language</button> | |
<p id="demo"></p> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment