i am doing a validation process, i need 2 suggession one is the way i am doing is correct? and how to validate the file field?
any one show me the right way?
var validateForm = function(form){ var submit = form.find(':submit'), elements = form.find(':input'), status = true; $('#contactForm').submit(function(event){ $(elements).each(function(){ var need = $(this).data('required'); if(need === 'text' && !$.trim($(this).val()).length){ $(this).css({border:'1px solid red'}); status = false; }else{ status = true; } if(need === 'textarea' && !$.trim($(this).val()).length){ status = false; }else{ status = true; } if(need === 'checkbox' && !$(this).prop('checked')){ status = false; }else{ status = true; } if(need === 'file'){ //how to check the file elment? }else{ status = true; } }) return status; }) } thank in advance!