Current location: Hot Scripts Forums » General Web Coding » JavaScript » type of file validation


type of file validation

Reply
  #1 (permalink)  
Old 08-31-04, 01:54 PM
rush989 rush989 is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
type of file validation

Hi everyone!

I have a form and a script that validates if fields are blank and if email address and phone number is accurate but I would like to validate one more thing. There is a file upload field and I would like to make sure that only picture files are being uploaded.

I've tried to find a script to exempt file types from being uploaded and I've found a few that do that but I cant implement them because they conflict with my current validation script.

The one that I have now that checks the other fields is:

Code:
<script language="JavaScript">
<!-- // ignore if non-JS browser
function Validator(form1)
{
  var error = "";
 
  if (form1.first_name.value == "")
  {
    error += "Please fill in you first name. \n";
  }
  
  if (form1.last_name.value == "")
  {
    error += "Please fill in you last name. \n";
  }
  
  if (form1.description.value == "")
  {
    error += "Please provide a description of what you would like done. \n";
  }
  
    if (form1.initials.value == "")
  {
    error += "Please fill in your initials. \n";
  }
  
  var digits = "0123456789-()";

  if (form1.phone_number.value == "")
  {
    error += "Please fill in your phone number. \n";
  }
  for (var i = 0; i < form1.phone_number.value.length; i++)
  {
    temp = form1.phone_number.value.substring(i, i+1)

    if (digits.indexOf(temp) == -1 &&
     form1.phone_number.value != "")
    {
      error += "You phone number must be in the format 555-555-5555. \n";
      break;
    }
  }
 if (form1.email_address.value == "")
  {
    error += "You must include an accurate email address. \n";
  }
  if ((form1.email_address.value.indexOf ('@',0) == -1 ||
   form1.email_address.value.indexOf ('.',0) == -1) &&
   form1.email_address.value != "")
  {
    error += "Please verify that your email address is valid. \n";
  }
if (error != "")
  {
    alert(error);
    return (false);
  } else {
    return (true);
  }
}
// -->
</script>
Then there is the
Code:
onSubmit="return Validator(this);"
in the form tag


What should I add to the code to validate the file upload fields (named upload, upload2, upload3, upload4, and upload5)? Thanks!!

Best Regards,
Adam
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
file upload csmaster2005 PHP 1 06-16-04 06:57 PM
Select one type of file only from directory Bonzo PHP 6 04-27-04 04:58 AM
Getting the created file (fopen/fwrite) Programme PHP 5 02-14-04 03:09 PM
Please I Need help before all my hair is gone! LisatheNovice Perl 6 11-22-03 03:05 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM


All times are GMT -5. The time now is 10:30 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.