I have attempted to apply a custom validation rule using jQuery as below
<script type="text/javascript">
$(document).ready(function(){
jQuery.validator.addMethod("notaccept", function(value, element, param) {
return value.match(new RegExp("." + param + "$"));
}, "<img src='../template/images/error.gif' alt='Only alphabet allowed.'>");
$("#frm1").validate({
rules: {
$('input[id^=txt_field]'): {
notaccept: "[a-zA-Z]+" }
}
});
});
</script>
The issue is the usage of element prefix selector in the above code doesn't work. I generate multiple field of the format txt_field11
, txt_field12
and so on dynamically.
Can I apply the above validation on multiple elements as in my case?