我正在使用输入类型文件上传文件,我想检查名称是否包含印地文字体或英文字体。
下面是我的代码。
<!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>
Run Code Online (Sandbox Code Playgroud)
印地语字符的字符代码为2309至2361。
尝试这个
function hasHindiCharacters(str)
{
return str.split("").filter( function(char){
var charCode = char.charCodeAt(); return charCode >= 2309 && charCode <=2361;
}).length > 0;
}
Run Code Online (Sandbox Code Playgroud)
您可以使用此方法
hasHindiCharacters("?asd"); //outputs true
hasHindiCharacters("asd"); //outputs false
Run Code Online (Sandbox Code Playgroud)
演示
function hasHindiCharacters(str)
{
return str.split("").filter( function(char){
var charCode = char.charCodeAt(); return charCode >= 2309 && charCode <=2361;
}).length > 0;
}
Run Code Online (Sandbox Code Playgroud)