I’m using the jQuery Validate plugin and want to validate an input field using a fixed amount of numbers with a dash in the middle like so: XXXXXX-XXXX. I know how to validate numbers but how can I get the plugin to validate this specific format?!
Thanks!
You could use a regex. Add a custom validator method as illustrated here:
And then attach it to the input element that you need to validate:
or if you are using it with the form:
And here’s a live demo.