I have a form and I upload a file and I have to verify that the filename has this format input##.txt
, where ##
are digits.
我有一个表单,我上传了一个文件,我必须验证文件名是否有这个格式的输入##。txt,其中##是数字。
Until now I've had a validator on the upload input and the regular expression that I found is input\d{2}\.txt
, but is not enough because the FileUpload control's filename looks like this :
到目前为止,我在上传输入上有一个验证器,我找到的正则表达式是input\d{2}\。txt,但还不够,因为FileUpload控件的文件名如下所示:
C:\Documents and Settings\xyz\Desktop\input01.txt
C:\Documents and Settings\xyz\Desktop\ input01.txt
and I need to validate only the part with input01.txt
.
我只需要用input01.txt对部分进行验证。
Could anyone help me?
有人能帮助我吗?
1 个解决方案
#1
1
Try this:
试试这个:
var fileName = Path.GetFileName(path);
var regex = new Regex("input\d{2}.txt", RegexOptions.IgnoreCase);
var isValid = regex.Matches(fileName);
#1
1
Try this:
试试这个:
var fileName = Path.GetFileName(path);
var regex = new Regex("input\d{2}.txt", RegexOptions.IgnoreCase);
var isValid = regex.Matches(fileName);