开发者

jQuery validation - validate actual data

开发者 https://www.devze.com 2023-03-05 14:34 出处:网络
开发者_高级运维I want to validate that the inputted data, contains a phrase, such as \'%TAG%\'.So, if %TAG% is not present within the text, it doesn\'t validate.

开发者_高级运维I want to validate that the inputted data, contains a phrase, such as '%TAG%'. So, if %TAG% is not present within the text, it doesn't validate.

Any ideas how I can do this using the jQuery validation plugin? Thanks!


First Add a method to the validator

$.validator.addMethod("checkTAGPhrase", function(value, element) {
    return (/%TAG%/.test(value));
}, "Invalid.");

Next use this validation class on your input element

<input type="text" name="myInput" class="checkTAGPhrase">
0

精彩评论

暂无评论...
验证码 换一张
取 消