Skip to content

Instantly share code, notes, and snippets.

@mrjithin
Created October 27, 2021 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrjithin/42abf94a7e0b0e7f312e60f78926d035 to your computer and use it in GitHub Desktop.
Save mrjithin/42abf94a7e0b0e7f312e60f78926d035 to your computer and use it in GitHub Desktop.
(function ($) {
"use strict";
/*==================================================================
[ Focus Contact2 ]*/
$('.input2').each(function(){
$(this).on('blur', function(){
if($(this).val().trim() != "") {
$(this).addClass('has-val');
}
else {
$(this).removeClass('has-val');
}
})
})
/*==================================================================
[ Validate ]*/
var name = $('.validate-input input[name="name"]');
var email = $('.validate-input input[name="email"]');
var message = $('.validate-input textarea[name="message"]');
$('.validate-form').on('submit',function(){
var check = true;
if($(name).val().trim() == ''){
showValidate(name);
check=false;
}
if($(email).val().trim().match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{1,5}|[0-9]{1,3})(\]?)$/) == null) {
showValidate(email);
check=false;
}
if($(message).val().trim() == ''){
showValidate(message);
check=false;
}
return check;
});
$('.validate-form .input2').each(function(){
$(this).focus(function(){
hideValidate(this);
});
});
function showValidate(input) {
var thisAlert = $(input).parent();
$(thisAlert).addClass('alert-validate');
}
function hideValidate(input) {
var thisAlert = $(input).parent();
$(thisAlert).removeClass('alert-validate');
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment