Javascript file upload Verification

Source: Internet
Author: User
// Place it between

<Script language = "JavaScript">
<! --
// Check the upload object checkfileupload (form name, file type, whether to upload, file size, minimum image width, minimum Image Height, maximum image width, and maximum image height, the name of the form storing the width and the name of the form storing the height)
Function checkfileupload (Form, extensions, requireupload, sizelimit, minwidth, minheight, maxwidth, maxheight, savewidth, saveheight ){
Document. mm_returnvalue = true;
If (extensions! = '') Var Re = new Regexp (" \. ("+ extensions. Replace (/,/GI," | ") +") $ "," I ");
For (VAR I = 0; I <form. elements. length; I ++ ){
Field = form. elements [I];
If (field. type. touppercase ()! = 'File') continue;
If (field. value = ''){
If (requireupload) {alert ('select the uploaded file! '); Document. mm_returnvalue = false; field. Focus (); break ;}
} Else {
If (extensions! = ''&&! Re. Test (field. Value )){
Alert ('the file does not match the upload type! \ N only supports the following types: '+ extensions + '. \ N select a new file to be uploaded according to regulations. ');
Document. mm_returnvalue = false; field. Focus (); break;
}
Document. pu_uploadform = form;
Re = new Regexp (". (GIF | JPG | PNG | BMP | JPEG) $", "I ");
If (Re. Test (field. Value) & (sizelimit! = ''| Minwidth! = ''| Minheight! = ''| Maxwidth! = ''| Maxheight! = ''| Savewidth! = ''| Saveheight! = '')){
SetTimeout ('If (document. mm_returnvalue) document. pu_uploadform.submit () ', 500 );
Checkimagedimensions (field. Value, sizelimit, minwidth, minheight, maxwidth, maxheight, savewidth, saveheight );
}}}
}

// -->
</SCRIPT>

// Place it in <body>
Onsubmit = "checkfileupload (this, 'gif, JPG, JPEG, PNG, BMP ', true ,'','','','','','', ''); Return document. mm_returnvalue"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.