如何在ASP .NET的文件上传控件中验证.PDF文件 [英] how to validate a .PDF file in fileupload control in asp .net

查看:104
本文介绍了如何在ASP .NET的文件上传控件中验证.PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...

我希望javascript在文件上传控件中进行验证,以验证所选文件是否具有.PDF格式...我适合的不是.PDF格式的文件,那么它应该显示消息..

谢谢..

hi to all...

i want javascript to validate in file upload control to validate the selected file is with .PDF format or not... I fit isnot a .PDF format file then it should show message..

Thanks..

推荐答案

使用JavaScript,您可以使用正则表达式来获取文件扩展名,如下所示:

var extens =(//../.exec(myfile))吗? /[^.]+
Using JavaScript you can use regular expression to get file extension like this:

var extens=(/[.]/.exec(myfile)) ? /[^.]+


/.exec(myfile):未定义;

myfile是文件的地址或路径.这只是将字符串放在."之后. .然后,您可以使用if进行一些控制检查.像:

if(extens =="doc" || extens =="pdf")
{
//您的方法在这里
}
其他
{
alert(文件无效");
}


您也可以参考此以获得更多帮助:

http://www.coursesweb.net/javascript/check-file-type-before-upload_t [^ ]

希望这会有所帮助:)
/.exec(myfile) : undefined;

myfile is the address or the path of the file. This simply takes the part of the string after "." . Then you can place some control checks with if. Something like :

if(extens=="doc" || extens=="pdf")
{
//your method goes here
}
else
{
alert("file is invalid");
}


You can also refer to this for more help:

http://www.coursesweb.net/javascript/check-file-type-before-upload_t[^]

hope this helps :)


尝试这些

检查FileUpload控件的文件扩展名 [如何检查上传文件扩展名(JavaScript) [ ^ ]
Try these

Check file extension of FileUpload control[^]
How to check upload file extension (JavaScript)[^]


这篇关于如何在ASP .NET的文件上传控件中验证.PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆