Possible Duplicate:
reject if file name contains non english character
how to check file name contain non english character like Cisco-S11-POA1800005815-Inv04736851-100919重做没有.pdf i need to avoid non english character
Possible Duplicate:
reject if file name contains non english character
how to check file name contain non english character like Cisco-S11-POA1800005815-Inv04736851-100919重做没有.pdf i need to avoid non english character
// Disallow anything but a-z, 0-9, underscore, period, hyphen, and comma
var disallowed = /[^a-z0-9_.,-]/i;
if (disallowed.test( myFileName )){
// do something here
}
Add to the list of allowed characters as you see fit, but ensure that the hyphen is at the end of the list, or else escape it with \-
.
The proper answer depends on knowing your character set.
But a regular expression like this:
var re = /[\x80-\xFF]/;
if (re.match(...)) {
alert("File name contains non-ASCII character!");
}
is a quick answer.
Note that it will also complain if your file name contains any special symbols.
Maybe a whitelist, saying only the allowed characters, is a better option, something like this?
var re = /[^A-Za-z0-9_,.-]/;
if (re.match(...)) {
alert("File name contains non-ASCII character!");
}