Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个表格,我上传了一个文件,我必须验证文件名是否具有这种格式input##.txt,##数字在哪里。
input##.txt
##
到目前为止,我对上传输入和正则表达式都有一个验证器input\d{2}\.txt,但我发现它还不够,因为 FileUpload 控件的文件名如下所示:
input\d{2}\.txt
C:\Documents and Settings\xyz\Desktop\input01.txt
我只需要验证带有input01.txt.
input01.txt
有人可以帮我吗?
试试这个:
var fileName = Path.GetFileName(path); var regex = new Regex("input\d{2}.txt", RegexOptions.IgnoreCase); var isValid = regex.Matches(fileName);