开发者

How to check file name for non-ASCII characters via JS?

I am using jQuery Uploadify to upload a file directly to S3. Everything works so far.

What I need now is to validate the file via JS. To make sure that all characters are ASCII compatible.

How开发者_JAVA技巧 can this be done?


The printable ASCII characters start at 0x20 (space) to 0x7E (~). The RegExp to match this range is: [\x20-\x7E].

So, the final code:

var filename = "foo.bar";
if(/^[\x20-\x7E]+$/.test(filename)){
    //Valid, continue
} else {
    //Invalid, notify the user
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜