首先,我对JS不太了解,所以请耐心等待。我找到了这个免费的验证 JS 并将其实现到我的网站中,但是,在成功验证后,它并没有告诉您表单已提交。我的问题是,是否可以在成功验证时使此验证召唤 Apprise.js 警报?通知
$(document).ready(function(){
//global vars
var form = $("#ContactForm");
var name = $("#name");
var nameInfo = $("#nameInfo");
var email = $("#email");
var emailInfo = $("#emailInfo");
var subject = $("#subject");
var subjectInfo = $("#subjectInfo");
var message = $("#message");
//On blur
name.blur(validateName);
email.blur(validateEmail);
subject.blur(validateSubject);
//On key press
name.keyup(validateName);
subject.keyup(validateSubject);
message.keyup(validateMessage);
//On Submitting
form.submit(function(){
if(validateName() & validateEmail() & validateSubject() & validateMessage())
return true
else
return false;
});
//validation functions
function validateEmail(){
//testing regular expression
var a = $("#email").val();
var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
//if it's valid email
if(filter.test(a)){
email.removeClass("error");
emailInfo.text("");
emailInfo.removeClass("error");
return true;
}
//if it's NOT valid
else{
email.addClass("error");
emailInfo.text("Please type a valid e-mail address!");
emailInfo.addClass("error");
return false;
}
}
function validateName(){
//if it's NOT valid
if(name.val().length < 4){
name.addClass("error");
nameInfo.text("Name must be atleast 4 letters (include last name)!");
nameInfo.addClass("error");
return false;
}
//if it's valid
else{
name.removeClass("error");
nameInfo.text("");
nameInfo.removeClass("error");
return true;
}
}
function validateSubject(){
//if it's NOT valid
if(subject.val().length < 4){
subject.addClass("error");
subjectInfo.text("Subject must be atleast 4 characters!");
subjectInfo.addClass("error");
return false;
}
//if it's valid
else{
subject.removeClass("error");
subjectInfo.text("");
subjectInfo.removeClass("error");
return true;
}
}
function validateMessage(){
//it's NOT valid
if(message.val().length < 1){
message.addClass("error");
return false;
}
//it's valid
else{
message.removeClass("error");
return true;
}
}
});