. Could ...">

Regex for checking folder name and file name

I want to check the file name

The file or folder name should not contain \ /? % *: | "<>.

Could you suggest me a regex expression for use in preg_match ()?

Thanks.

+6
source share
4 answers

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. */ } 
+9
source

A regular expression that matches your requirements: ^[^\\/?%*:|"<>\.]+$

+6
source
 new RegExp('^[a-zA-Z--0-9_!]+$') 

http://regexpal.com/ try this site

+2
source
 new RegExp('^[^\\\\\/\?\%\*\:\|\"<>]+$') 

his work is for me. It basically takes:

 new RegExp('^[^\\/?%*:|"<>]+$') 
0
source

Source: https://habr.com/ru/post/889666/


All Articles