我想在我的对话框中放置验证。一个是空验证,第二个是电子邮件验证。
if (emailAndPasswordCheck) {
$( "#dialog-modal" ).dialog({
height: 160,
closeOnEscape: false,
modal: true
});
}
答案 0 :(得分:2)
jQuery validation plugin通常被广泛认可且易于使用。
答案 1 :(得分:1)
好的,您的电子邮件验证空验证代码与PHP文件相同 还可以从一些提到的版本的链接下载jquery - jquery-1.9.1.js。创建了一个abc,js abc.js
<script type="text/javascript" src="JScript/jquery-1.9.1.js"> </script>
<script type="text/javascript" src="JScript/newempcontact.js"></script>
<span id="validate_msg"></span>
<label id="lbl_frstname">* First Name :</label>
<input class="hover" type="text" id="txt_firstname" minlength="1" maxlength="26" placeholder="First Name"/>
<span class="sfirstname"></span>
<label id="lbl_pemail">* Personal Email :</label>
<input class="hover" type="text" id="txt_pemail" placeholder="Personal Email"/>
<span class="spemail"></span>
你可以放置任何地方.. 再创建一个带有任何名称的php文件,例如abc.php
<?php
if(isset($_POST['email'])){
$email = $_POST['email'];
if(filter_var($email, FILTER_VALIDATE_EMAIL) == false){
echo "This is not valid email id!";
}else{
echo "This is valid email id!";
};
}
?>
你的abc.js文件是: -
$(document).ready(function() {
$('#slct_pstate, #slct_tstate' ).bind('change click scroll ',function(e) {
fill_cities();
});
$('#slct_tstate').bind('change click scroll ',function(e) {
fill_cities();
});
email_validation()
//将form_nempcontact替换为您的表单名称 -
$('#submit').click(function() {
submit_fxn();
$('#form_nempcontact').submit(function(e) {
return false;
});
});
});
function email_validation(){
$('#txt_pemail').focusin(function(e) {
if($('#txt_pemail').val() == ''){
$('span.spemail').text('Go for valid email address').addClass('validatectrl');;
}
else{
emailvalidattion($('#txt_pemail').val());
}
}).blur(function(e) {
$('span.spemail').html('');
}).keyup(function(e) {
emailvalidattion($('#txt_pemail').val());
});
};//****
function emailvalidattion(email){
$.post('PHP/check.php', {email:email}, function(result){
$('span.spemail').text(result).addClass('validatectrl');
});
};//**
function submit_fxn(){
var check_flag = 0;
var fname = $('#txt_firstname');
var fname_val = fname.val();
var fname_dftlngth = fname.attr('minlength');
var fname_usrdftlngth = fname_val.length;
if(fname_usrdftlngth == 0 || fname_usrdftlngth < fname_dftlngth){
$(fname).css({
"background-color":"#FF0000",
"border":"soild 2px yellow"
});
check_flag = 1;
}else{
$(fname).css({
"background-color":"#FFFFFF"
});
}
if(check_flag == 1){
$("#form_nempcontact").submit(function() {
$("#validate_msg").text('');
});
}
if(check_flag == 0){
//---Write your code here
}
};
//您的CSS代码为 -
p.validate_msg {
border: 1px solid #FF0000;
font-weight: bold;
padding: 10px;
display:none;
margin-bottom:25px;
color:#FFFF00;
}
span.validatectrl, p.validatectrl {
color:#FFFF00;
font-family:"Times New Roman", Times, serif;
font-size:14px;
padding-left:8px;
}
span.validatectrlgreen {
color:#090;
padding-left:8px;
font-style:italic;
}
如果答案是正确的,请将其标记为答案