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.
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. */
}
The regex that meets your requirements: ^[^\\/?%*:|"<>\.]+$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With