jQuery validate: How to add a rule for regular expression validation?

前端 未结 13 1433
忘掉有多难
忘掉有多难 2020-11-22 07:41

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 m

13条回答
  •  旧时难觅i
    2020-11-22 08:30

    Have you tried this??

    $("Textbox").rules("add", { regex: "^[a-zA-Z'.\\s]{1,40}$", messages: { regex: "The text is invalid..." } })
    

    Note: make sure to escape all the "\" of ur regex by adding another "\" in front of them else the regex wont work as expected.

提交回复
热议问题