0
Good afternoon, I need to make an error message appear when the user does not put the email with "@". already has a function that already includes all fields a class when they are left unfilled.
Is there any way I can make a class appear just for the email field? and that it identifies if it will be with the "@"?
HTML:
<input type="text" name="Nome" placeholder="Nome..." class="quote-form-element" />
<input type="text" name="Cidade" placeholder="Cidade/UF..." class="quote-form-element quote-form-client-email last" />
<input type="text" name="Número de Telefone" placeholder="Telefone..." class="quote-form-element" />
<input type="text" onblur="validacaoEmail(f1.email)" name="Endereço de Email" placeholder="E-mail..." class="quote-form-element quote-form-client-email last" />
Javascript
$( '.send-contact' ).click( function() {
var contactForm = $( this ).parent();
var contactFormParent = contactForm.parent().parent();
var fields = {};
var fieldID = 0;
var fieldName = '';
var fieldValue = '';
var clientName = '';
var clientEmail = '';
var clientMessageTitle = '';
var errorFound = false;
contactForm.find( '.contact-form-element' ).each( function( fieldID ) {
fieldName = $( this ).attr( 'name' );
if( typeof fieldName == 'undefined' || fieldName === false ) {
fieldName = $( this ).data( 'name' );
}
if( $( this ).hasClass( 'checkbox' ) ) {
fieldValue = $( this ).data( 'checked' ) == 'yes' ? $( this ).children( '.checkbox-values' ).children( '.checkbox-value-checked' ).text() : $( this ).children( '.checkbox-values' ).children( '.checkbox-value-unchecked' ).text();
}
else {
fieldValue = $( this ).is( 'input' ) || $( this ).is( 'textarea' ) || $( this ).is( 'select' ) ? $( this ).val() : $( this ).text();
if( ( $( this ).is( 'input' ) && fieldValue == '' ) || ( $( this ).is( 'textarea' ) && fieldValue == '' ) || ( $( this ).is( 'select' ) && fieldValue == '-' ) ) {
errorFound = true;
$( this ).addClass( 'error' );
}
else {
$( this ).removeClass( 'error' );
}
}
if( $( this ).hasClass( 'contact-form-client-name' ) ) clientName = $( this ).val();
if( $( this ).hasClass( 'contact-form-client-email' ) ) clientEmail = $( this ).val();
if( $( this ).hasClass( 'contact-form-client-message-title' ) ) clientMessageTitle = $( this ).val();
fields[fieldID] = { 'name': fieldName, 'value': fieldValue };
fieldID++;
});
if( errorFound == false ) {
$.ajax({ url: '_assets/submit.php',
data: { 'send': 'contact-form', 'values': fields, 'clientName': clientName, 'clientEmail': clientEmail, 'clientMessageTitle': clientMessageTitle },
type: 'post',
success: function( output ) {
contactForm.children( '.contact-form-thanks' ).fadeIn( 300 );
}
});
}
});
I tried to use, but also did not work, when I press the button it already presents direct the message that was sent
– Pedro Henrique Kuzminskas