You could use a regex. Add a custom validator method as illustrated here:
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return re.test(value);
},
"Please check your input."
);
And then attach it to the input element that you need to validate:
$('#id_of_textbox').rules('add', { regex: '^[0-9]{6}-[0-9]{4}$' })
or if you are using it with the form:
$('#id_of_form').validate({
rules: {
name_of_textbox: {
regex: '^[0-9]{6}-[0-9]{4}$'
}
},
messages: {
name_of_textbox: {
regex: 'Please provide a valid input for this field'
}
}
});
And here's a live demo.