用CustomerValidator 来验证 FileUpload控件的方法

How to check the FileUpload control on Client code(Brower)
First the FileUpload control is support Validator control
so we can use RegularExpressionValidator, CustomerValidator, because we can't set Ignore case property on Regular Expression Validator , so  i like use CustomerValidator to check the Extension.
The code on below, you can copy the code block to your page, and add one CustomerValidator

用CustomerValidator 来验证 FileUpload控件的方法   < script type = " text/javascript " >
用CustomerValidator 来验证 FileUpload控件的方法
function  CheckFile(sender,arg)
用CustomerValidator 来验证 FileUpload控件的方法
{
用CustomerValidator 来验证 FileUpload控件的方法    
var enableExt =["jpg","gif","bmp","png"]; // add your enable extension on that
用CustomerValidator 来验证 FileUpload控件的方法
    if (arg.Value=="")
用CustomerValidator 来验证 FileUpload控件的方法    
{
用CustomerValidator 来验证 FileUpload控件的方法        arg.IsValid 
=true;
用CustomerValidator 来验证 FileUpload控件的方法    }

用CustomerValidator 来验证 FileUpload控件的方法    
else
用CustomerValidator 来验证 FileUpload控件的方法    
{
用CustomerValidator 来验证 FileUpload控件的方法        
var temp = arg.Value.split(".");
用CustomerValidator 来验证 FileUpload控件的方法        
var extension = temp[temp.length-1];
用CustomerValidator 来验证 FileUpload控件的方法        extension 
= extension.toLowerCase();
用CustomerValidator 来验证 FileUpload控件的方法        
var isValid = false;
用CustomerValidator 来验证 FileUpload控件的方法        
用CustomerValidator 来验证 FileUpload控件的方法        
for(i=0;i<enableExt.length;i++)
用CustomerValidator 来验证 FileUpload控件的方法        
{
用CustomerValidator 来验证 FileUpload控件的方法           
if (extension==enableExt[i])
用CustomerValidator 来验证 FileUpload控件的方法           
{
用CustomerValidator 来验证 FileUpload控件的方法                isValid
=true;
用CustomerValidator 来验证 FileUpload控件的方法           }

用CustomerValidator 来验证 FileUpload控件的方法        }

用CustomerValidator 来验证 FileUpload控件的方法        arg.IsValid 
= isValid;
用CustomerValidator 来验证 FileUpload控件的方法    }

用CustomerValidator 来验证 FileUpload控件的方法}

用CustomerValidator 来验证 FileUpload控件的方法
< / script>

你可能感兴趣的:(fileupload)