Skip to content

Instantly share code, notes, and snippets.

@mavitm
Last active March 10, 2017 10:40
Show Gist options
  • Save mavitm/d77e8acdea3a48fef70586194474b714 to your computer and use it in GitHub Desktop.
Save mavitm/d77e8acdea3a48fef70586194474b714 to your computer and use it in GitHub Desktop.
function formKontrol(form) {
var hata = 1;
$(".zorunlu").removeClass("uyari");
$(".zorunlu", form).each(function (i) {
if (
$(this).val() == "" ||
$(this).val() == 0 ||
$(this).val() == '0' ||
$(this).val() == 'undefined' ||
$(this).val() == null ||
$(this).val() == false
) {
$(this).addClass("uyari");
var eleman = $(this);
hata = 2;
return false;
}
if($(this).attr("type") == "email"){
var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+.)+([.])+[a-zA-Z0-9.-]{2,4}$/;
if (regex.test($(this).val()) != true){
$(this).addClass("uyari"); hata = 2;
}
var reg = new RegExp("\[ÜĞŞÇÖğıüşöçİ]");
if(reg.test($(this).val(),reg)){
$(this).addClass("uyari"); hata = 2;
}
}
});
if (hata > 1) {
//$.scrollTo($(".uyari"), {duration: 1000});
var target = $(".uyari");
$('html, body').animate({ scrollTop: (target.offset().top - 60) }, 500);
return false;
}
return true;
}
$(document).ready(function () {
$("form").on("submit", function(){
var kontrol = formKontrol($(this));
if(kontrol == false){
/*class uyari olan elemanin paren icindeki label text veya
kendi datasindaki texti alert gosterebilirsin yada .uyari class icin
gosterisli bir css yazip bos olan elemani belirir bir sekilde vurgulayabilirsin*/
return false;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment