Skip to content

Instantly share code, notes, and snippets.

@agragregra
Created March 21, 2015 15:52
Show Gist options
  • Save agragregra/b929e3c441962c429622 to your computer and use it in GitHub Desktop.
Save agragregra/b929e3c441962c429622 to your computer and use it in GitHub Desktop.
Easy Form Validator
//Easy Form Validator
//Example: $("form").evalid("Error message");
//Author URL: http://webdesign-master.ru
(function($) {
$.fn.evalid = function(req_text) {
$(this).find("input[type], textarea").each(function() {
$(this).after("<p class='form_error_message'>" + req_text + "").next().hide();
});
$(this).submit(function(event) {
$(this).find("input[type], textarea").each(function() {
var attr = $(this).attr("data");
if (typeof attr !== typeof undefined && attr !== false) {
if($(this).val() == "") {
$(this).addClass("input_error");
$(this).next().show();
event.preventDefault();
} else {
$(this).removeClass("input_error");
$(this).next().hide();
};
};
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment