Reputation: 375
I want to validate a file name
Name of file or folder should not contain \ / ? % * : | " < > .
Could you please suggest me the regex expression to use in preg_match()?
Thanks.
Upvotes: 8
Views: 21489
Reputation: 1271
new RegExp('^[^\\\\\/\?\%\*\:\|\"<>]+$')
its work for me. Basically it takes:
new RegExp('^[^\\/?%*:|"<>]+$')
Upvotes: 1
Reputation: 1564
new RegExp('^[a-zA-Zа-яА-Я0-9_!]+$')
http://regexpal.com/ try this site
Upvotes: 3
Reputation: 3826
It would be more efficient to use the strpbrk() function.
if (strpbrk($filename, "\\/?%*:|\"<>") === FALSE) {
/* $filename is legal; doesn't contain illegal character. */
}
else {
/* $filename contains at least one illegal character. */
}
Upvotes: 14