繁体   English   中英

使用联系表7验证姓名字段

[英]Validating Name Field With Contact Form 7

我正在寻找有关联系表7验证姓名字段的帮助。我已经收到大量垃圾邮件,并且姓名字段中包含数字“ 59ab ...”。 寻找一种验证数字以外的方式的方法。 我尝试使用jQuery,但没有成功。

较早尝试过但未成功。

$( ".your-name input" ).change(function() {
var num = $(this).text();
if ($.isNumeric(num)) {
    $(this).attr('class', 'numb');
} else {
    $(this).attr('class', 'noNumb');
}

});

只需将$(this).text()更改$(this).val()就可以解决您的问题。 检查以下代码片段以供参考。

 $(".myinput").change(function() { var num = $(this).val(); if ($.isNumeric(num)) { $(this).attr('class', 'numb'); } else { $(this).attr('class', 'noNumb'); } }); 
 .numb { border-color: green; } .noNumb { border-color: red; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="myinput"> 

更新 :检查以下代码段。 在这里,我使用正则表达式来检测输入中是否有任何数字。

 $(".myinput").change(function() { var num = $(this).val().replace(/[^0-9]/gi, ''); if ($.isNumeric(num)) { $(this).attr('class', 'numb'); } else { $(this).attr('class', 'noNumb'); } }); 
 .numb { border-color: green; } .noNumb { border-color: red; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="myinput"> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM