By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,288 Members | 1,695 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,288 IT Pros & Developers. It's quick & easy.

Restricting access to input file based on File Types

P: 6

I got a problem like i write a input file element like this

<input type="file" name="testfile" >

When i execute this i get a text box with browse. when i click browse i am abl e to see all files. is there any way to restrict file types like,i want to select only xml files to be uploaded.

and i want to display some message if i select some other file type rather that xml files (client side validation).

I am using jsp and html.

please help me.
Oct 17 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 5,390
hi ...

for the validation you may use the onchange-event to call a function like this:

[HTML]<script type="text/javascript">
function check_field(obj) {
if (!(/.xml$/.test(obj.value))) {
alert('no xml file');

<input type="file" name="testfile" onchange="check_field(this);">[/HTML]
kind regards
Oct 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.