In our scripting sometimes we need to upload such documents , at that time there should be a validation for proper file.
For example in your system suppose there is a field for image upload , that is obvious in that field only image formats are allowed (jpg,jpeg,png,gif etc.). At that time you have to give a validation on that field.
In javascript to find the extension and validation here is your code :
<script type="text/javascript">
var str = document.form1.file.value.toLowerCase();
// to convert the value in lower case
var split = str.split("."); // split the value by "."
var s =split.length; // find the length
var ext = (split[s-1]); // and then store the extension in variable
if((ext=='jpg') || (ext=='png') || (ext=='jpeg') || (ext=='gif') ){ }
else {
alert("Your message for proper input") ;
return false
}
</script>
enjoy.....
Comments
Post a Comment