我的代码看起来像这样。帮帮我
$('#form').validate({
errorElement: "span", // contain the error msg in a span tag
errorClass: 'help-block',
ignore: "",
rules: {
CountryName: {
required: true,
regex: /^[a-zA-Z]+$/
}
},
messages: {
CountryName: {
required: "Enter Country name",
regex: "Enter Correct Country name",
},
},
答案 0 :(得分:2)
没有regex
规则,它被称为pattern
,来自additional-methods
文件
jQuery(function($) {
$('#form').validate({
errorElement: "span", // contain the error msg in a span tag
errorClass: 'help-block',
ignore: "",
rules: {
CountryName: {
required: true,
pattern: /^[a-zA-Z]+$/
}
},
messages: {
CountryName: {
required: "Enter Country name",
pattern: "Enter Correct Country name",
}
}
});
});

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/additional-methods.js"></script>
<form id="form" method="post" action="">
<input name="CountryName" />
<input type="submit" value="Save" />
</form>
&#13;