I really have no idea why my custom rule in jquery isnt working. all it is is looking for a substring in a text, making it required if it DOESNT appear, not required if it does. I am using the jquery validate library. I hope its something simple… please help!
jQuery.noConflict();
(function($) {
$(function() {
$("#frmUpdateCC").validate({
errorContainer: "#updateProfileCC",
errorPlacement: function(error, element) {},
rules: {
txtCardNo1: {
required: true,
creditcard: function() {
var str = $('#txtCardNo1').val();
str = (str.indexOf("xxxxxx"));
return (str != 6 );
}
}
cboMonth1: "required",
cboCard1: "required",
}
});
});
})(jQuery);
Ive tried using !== 6, !=’6′, and other variations thereof
Well,
str.indexOf("xxxxxx")is going to return the start position of"xxxxxx"in your stringstr.So, if
strcontains'xxxxxx', your statements would only evaluate as true if'xxxxxx'begins as position 6. Did you mean to test for str.length maybe?Otherwise, why not simply do: