I am using the jQuery validation plugin. Great stuff! I want to migrate my existing ASP.NET solution to use jQuery instead of the ASP.NET validators. I am missing a replacement for the regular expression validator. I want to be able to do something like this:
$('Textbox').rules('add', { regularExpression: '^[a-zA-Z'.\s]{1,40}$' })
How do I add a custom rule to achieve this?
Thanks to the answer of redsquare I added a method like this:
Now all you need to do to validate against any regex is this:
Additionally, it looks like there is a file called
additional-methods.jsthat contains the method "pattern", which can be aRegExpwhen created using the method without quotes.Edit
The
patternfunction is now the preferred way to do this, making the example: