每行的多行php验证
请参考上图。。我对jquery非常陌生,我开发了一个php表单来输入数据。我想限制用户在输入错误值时离开文本字段。 范围:0到50。 它也应该接受AB、NR 你知道如何做到这一点吗 我非常感谢您的快速回复 我换了每行的多行php验证,php,jquery,Php,Jquery,请参考上图。。我对jquery非常陌生,我开发了一个php表单来输入数据。我想限制用户在输入错误值时离开文本字段。 范围:0到50。 它也应该接受AB、NR 你知道如何做到这一点吗 我非常感谢您的快速回复 我换了 <script> $.validator.addMethod("custom_number", function(value, element) { return this.optional(element) || value == "AB" || value == "NF
<script>
$.validator.addMethod("custom_number", function(value, element) {
return this.optional(element) || value == "AB" || value == "NF" ||
value.match(/^[0-9,\+-]+$/);
}, "Please enter a valid number, or 'AB'");
$(document).ready(function(){
$("#form").validate({
rules: {
'hd[]': {
required: false,
custom_number: true
}
}
});
});
</script>
$.validator.addMethod(“自定义_编号”,函数(值,元素){
返回此值。可选(元素)| |值==“AB”| |值==“NF”|
匹配(/^[0-9,\+-]+$/);
},“请输入有效数字,或“AB”);
$(文档).ready(函数(){
$(“#表格”)。验证({
规则:{
“hd[]”:{
必填项:false,
自定义编号:true
}
}
});
});
与
变量接受值=数组(“AB”、“NR”、“01”、“02”、“03”、“04”、“05”、“06”、“07”、“08”、“09”、“10”);
功能(针、干草堆){
var length=haystack.length;
对于(变量i=0;i
希望我能接受01到10和'AB'和'NR'
但它并不成功。有没有办法提供范围和字母表?var accept_values=array(“AB”,“NR”);
var accept_values = array("AB","NR");
function inArray(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
if(haystack[i] == needle) return true;
}
return false;
}
var success = 0;
$("input[type='text']").each(function(){
if(!in_array(accept_values, $(this).val())) {
success = 1;
}
});
if(success == 1){
alert("You have entered an invalid value");
return false;
}
//do success
功能(针、干草堆){
var length=haystack.length;
对于(变量i=0;i
var accept_values=数组(“AB”、“NR”);
功能(针、干草堆){
var length=haystack.length;
对于(变量i=0;i
希望您的文本框具有相同的css类(例如:checkrow)
Jquery代码(未测试)
希望您的文本框具有相同的css类(例如:checkrow) Jquery代码(未测试)
请根据您的要求/需要进行修改:
function validate(){
$('.theory').each(function(){
if($(this).val() == ''){
alert('Please enter value.');
return false;
}else{
if($(this).val() < 0 || $(this).val() > 50 ){
alert('Please enter correct value.');
return false;
}
}
});
return true;
}
函数验证(){
$('.theory')。每个(函数(){
if($(this.val()=''){
警报('请输入值');
返回false;
}否则{
if($(this.val()<0 | |$(this.val()>50){
警报('请输入正确的值');
返回false;
}
}
});
返回true;
}
请根据您的要求/需要进行修改:
function validate(){
$('.theory').each(function(){
if($(this).val() == ''){
alert('Please enter value.');
return false;
}else{
if($(this).val() < 0 || $(this).val() > 50 ){
alert('Please enter correct value.');
return false;
}
}
});
return true;
}
函数验证(){
$('.theory')。每个(函数(){
if($(this.val()=''){
警报('请输入值');
返回false;
}否则{
if($(this.val()<0 | |$(this.val()>50){
警报('请输入正确的值');
返回false;
}
}
});
返回true;
}
我已尝试使用jquery验证程序解决您的问题
检查它是否符合您的要求,或者您希望更改某些内容
<script src='
http://code.jquery.com/jquery-latest.min.js '></script>
<script src='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js'></script>
<script>
$(document).ready(function(){
$('#frm').validate();
$(".inp_text").each(function(){
$(this).rules("add", {
required: true,
checkValue: true
});
});
$.validator.addMethod("checkValue", function(value, element) {
var response = ((value > 0)&&(value <= 50))||((value == 'AB')||(value =='NR'));
return response;
}, "invalid value");
})
</script>
<form id='frm'>
<input type='text' name='inp_text' class='inp_text'/><br>
<input type='text' name='inp_text1' class='inp_text'/><br>
<input type='submit' name=''/>
</frm>
$(文档).ready(函数(){
$('#frm').validate();
$(“.inp_text”)。每个(函数(){
$(此).rules(“添加”{
要求:正确,
checkValue:true
});
});
$.validator.addMethod(“checkValue”,函数(值,元素){
var response=((value>0)和&(value我已尝试使用jquery验证程序解决您的问题
检查它是否符合您的要求,或者您希望更改某些内容
<script src='
http://code.jquery.com/jquery-latest.min.js '></script>
<script src='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js'></script>
<script>
$(document).ready(function(){
$('#frm').validate();
$(".inp_text").each(function(){
$(this).rules("add", {
required: true,
checkValue: true
});
});
$.validator.addMethod("checkValue", function(value, element) {
var response = ((value > 0)&&(value <= 50))||((value == 'AB')||(value =='NR'));
return response;
}, "invalid value");
})
</script>
<form id='frm'>
<input type='text' name='inp_text' class='inp_text'/><br>
<input type='text' name='inp_text1' class='inp_text'/><br>
<input type='submit' name=''/>
</frm>
$(文档).ready(函数(){
$('#frm').validate();
$(“.inp_text”)。每个(函数(){
$(此).rules(“添加”{
要求:正确,
checkValue:true
});
});
$.validator.addMethod(“checkValue”,函数(值,元素){
var response=((value>0)和&(value)请发布html代码请发布html代码谢谢我会尝试。谢谢我会尝试。另请参阅jquery验证程序请参阅jquery验证程序我希望此()对数组有效;我添加了e.preventDefault();e.stopPropagation();this.focus();警报后,但它不起作用。抱歉,没有得到它,请解释一点意味着他不能在其他文本字段中输入?检查此小提琴用户不应被允许离开文本框,如果他输入了错误的值,他应该保持在同一文本框中,如果他输入了无效的值我想要这个()数组的效果;我添加了e.preventDefault();e.stopPropagation();this.focus();警报后,但它不起作用。抱歉,没有得到它,请解释一点,这意味着他不能在其他文本字段中输入?检查此小提琴用户不应被允许离开文本框,如果他输入了错误的值,他应该留在同一文本框中,如果他输入了无效的值