How to set limit of input file field with jQuery

Hello everyone!

By default, in current implementation of HTML language in modern browsers input tag doesn’t support limit for uploading files.
And if you need to set limit of maximum uploading files in your field:

<input type="file" name="photos" multiple />

you can use a simple jQuery snippet:

$(document).ready(function(){
	var limit_of_files = 5;
	$('input[type="file"]').on('change',function(){

		if($(this).prop('files').length>limit_of_files)
		{
			alert('You exceeded limit for uploading files! Maximum of uploading files is 5!');
			$(this).val('');
			return false;
		}

	});
});