我需要用jquery validate来验证一个文本区域。我正在寻找正则表达式来检查由空格分隔且长度超过5个字符的多个带引号的字符串。:
“引用的文本..”"some text“"another quoted string”=好
“带引号的文本..”另一个带引号的字符串“=错误
“引用的文本..”“good”“另一个带引号的字符串”=不正确
下面只检查第一个引用的文本...(“带引号的字符串长度大于5”-->此过程通过,但不应通过)
$(document).ready(function()
{
$.validator.addMethod("coll_regex", function(value, element) {
return this.optional(element) || /"(.*?)"/.test(value);
}, "Message here......");
$("#f_coll").validate(
{
rules:{
'coll_txt':{
required: true,
minlength: 5,
maxlength: 200,
coll_regex: true
}
},
messages:{
'coll_txt':{
required: "Textarea is empty...",
minlength: "Length must be, at least, 5 characters..",
maxlength: "You exceeded the max_length !",
coll_regex: "Use the quotes...."
}
},
errorPlacement: function(error, element) {
error.appendTo(element.next());
}
});
});有没有这样做的正则表达式?会很棒的..。谢谢
发布于 2012-08-18 08:38:08
您要查找的正则表达式是/^("[^\".]{5,}" )*"[^\".]{5,}"$/
'"abcdefg" "abcdefg" "01324"'.match(/^("[^\".]{5,}" )*"[^\".]{5,}"$/) //--> true
'"abcdefg" "123" "01324"'.match(/^("[^\".]{5,}" )*"[^\".]{5,}"$/) //--> false
'"abcdefg" "" "01324"'.match(/^("[^\".]{5,}" )*"[^\".]{5,}"$/) //--> false编辑:
这个更精确:/^("[^\".]{5,}"\s+)*"[^\".]{5,}"$/它允许组之间的任何空格,而不仅仅是一个空格。
https://stackoverflow.com/questions/12014700
复制相似问题