Q . Using JavaScript how to check string contains Hindi font?

Brad Johnson. asked, Jun 01 ' 2016

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>

 

  • JavaScript
  • hindi
  • fonts

1 Answers

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

Leave a Ansewer