I am uploading a file using input type file I want to check that the name contains hindi font or english font.
Below is my code.
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$("document").ready(function () {
$("#upload").change(function () {
var filename = $(this).val().replace(/^.*[\\\/]/, '')
alert(filename);
});
});
</script>
</head>
<body>
<div>
<input type="file" name="upload" id="upload" value="upload" />
</div>
</body>
</html>
Hindi characters' character code is from 2309 to 2361.
try this
function hasHindiCharacters(str)
{
return str.split("").filter( function(char){
var charCode = char.charCodeAt(); return charCode >= 2309 && charCode <=2361;
}).length > 0;
}
You can use this method
hasHindiCharacters("अasd"); //outputs true
hasHindiCharacters("asd"); //outputs false
DEMO
function hasHindiCharacters(str)
{
return str.split("").filter( function(char){
var charCode = char.charCodeAt(); return charCode >= 2309 && charCode <=2361;
}).length > 0;
}
console.log(hasHindiCharacters("अasd")); //outputs true
console.log(hasHindiCharacters("asd")); //outputs false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With