试图用10位电话号码,没有空格或其他任何其他字符验证。我认为我有正确的REG EX,但不确定如何实现代码,因此它也没有空间。
我到目前为止所做的:添加在jquery.validationengine-en.js
中// ADDED for 10 digit phone
"phone10": {
"regex": /^[d ]+$/,
// alertText brings up two error messages so using alertText2
"alertText2": " numbers only: xxxxxxxxxx",
},
我然后在jquery.validationengine.js中添加了phone10案例语句:
case "phone10":
errorMsg = methods._getErrorMessage(form, field, rules[i], rules, i,
options, methods._phone10Size);
break;
,并在下面放置函数,称为_phone10size:
_phone10Size: function(field, rules, i, options) {
var max = rules[i + 1];
var len = field.val().length;
if (len < 10) {
var rule = options.allrules.phone10;
return 10 + rule.alertText2;
}
},
哦,是的,我还必须将maxlength =" 10"放在表单输入字段上。我知道它不是优雅的,甚至不是"合适的"。有人可以告诉我如何仅实现这10位不允许空间的数字吗?谢谢。
仅针对仅10个数字(无空格)的解决方案。对于我所说的班上的课程:
class="validate[required,custom[onlyNumber],minSize[10],maxSize[10]] text-input"
并将功能仅添加到jquery.validationengine-en.js文件中的第97行中的函数:
"onlyNumber": {
"regex": /^[0-9]+$/,
"alertText": "* Numbers only"
},
您可以在jquery.validation.engine-en.js中使用'数字'示例中的默认validate函数:
class="validate[required,custom[number],minSize[10],maxSize[12]] text-input"
您可以使用与下面所示的电话功能相同的电话功能:
class="validate[required,custom[phone]] text-input" type="text"