Regular expression for valid filename

后端 未结 10 1585
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 18:11

I already gone through some question in StackOverflow regarding this but nothing helped much in my case.

I want to restrict the user to provide a filename that shoul

10条回答
  •  再見小時候
    2020-12-29 19:05

    Copied from @Engineer for future reference as the dot was not escaped (as it should) in the most voted answer.

    This is the correct expression:

    string regex = @"^[\w\-\. ]+$";
    

提交回复
热议问题