How to set limit of input file field with jQuery

Hello everyone!

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

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

you can use 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;
		}

	});
});