Hiya hope this help :)) Working Demo : http://jsfiddle.net/2FByp/2/
Like @zerkms said please be very clear what is not working. you can always refer to the validation plugin documentation && this might help you as well: using the jquery validation plugin, how can I add a regex validation on a textbox?
NOTE Please make sure all the rules are added correctly and compare your implementation with the jsfiddle above, else flick me jsfiddle I might be help BUT this js fiddle will help you to find out why it is not working. :)
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script type="text/javascript">
</script>
<form method="post" id="myForm">
Name regex (alphanumeric):<input type="text" name="name" />
<input type="submit" value="Go" />
</form>
JQuery Code
$(function() {
$.validator.addMethod("nameRegex", function(value, element) {
return this.optional(element) || /^[a-z0-9\-]+$/i.test(value);
}, "Username must contain only letters, numbers, or dashes.");
$("#myForm").validate({
rules: {
"name": {
required: true,
nameRegex: true,
minlength: 8
}
},
messages: {
"name": {
required: "You must enter a login name",
nameRegex: "Contain only letters, numbers."
}
}
});
});
Hope this is helpful cheers!