$(document).ready(function() { $('#envia').click(function() { //alert('hola'); //$('#continua').removeAttr('onclick'); //$('#div_cont').css('display', 'none'); envia=true; $(".oblig_dades").each(function (index) { id="#"+$(this).attr('id'); la_id="#la_"+$(this).attr('id'); $(id).css('border-color', '#ccc'); $(la_id).css('color', '#444444'); if ($(this).val()=="") { $(id).css('border-color', 'red'); $(la_id).css('color', 'red'); envia=false; } }); if (envia==true) { if (!validar_email($("#email").val())) { envia=false; $("#la_email").css('color', 'red'); $("#email").css('border-color', 'red'); } } if (envia==true) { var parametros = { "nom" : $("#nom").val(), "email" : $("#email").val(), "telefon" : $("#telefon").val(), "missatge" : $("#missatge").val(), "lang" : 'esp' }; $.ajax({ data: parametros, url: 'jenvia_mail.php', type: 'get', success: function (response) { $("#text").html(response); } }); } }); function validar_email(valor) { // creamos nuestra regla con expresiones regulares. var filter = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/; // utilizamos test para comprobar si el parametro valor cumple la regla if(filter.test(valor)) return true; else return false; } });