Validate Filename Before Uploading Image Using JavaScript
Today’s helpful snippet will help you validate the filename of an image that’s being uploaded onto the server using JavaScript, making sure that it doesn’t consist of any unwanted spaces or invalid characters. This basically prevents the user from uploading or submitting any image file unless the proper format is used.
<script language=”javascript"> function Checkfiles() { var fup = document.getElementById('filename'); var fileName = fup.value; var ext = fileName.substring(fileName.lastIndexOf('.') + 1); if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "doc") { return true; } else { alert("Upload Gif or Jpg images only"); fup.focus(); return false; } } </script> <li> <div> <input type="file" id="logo1" onchange="Checkfiles()" multiple accept='image/*' name="txtLogoFileName" tabindex="20" value="<?php if($_POST["txtLogoFileName"]) echo $_POST["txtLogoFileName"]; else echo($LogofileName); ?>" /> </div> </li>
Incoming search terms for the article:
- javascript картинка gif
- background designs
- javascript validation for div image upload
- preview image before upload using javascript
- tutorial for javascript validation on a button to upload an image
- validate 6 image uploads javascript
- validate filename before upload using html
- validating directory or filename in javascript
- validating multiple images uploading in javascript
- javascript validate upload file name