jQuery 文本框验证

发布于 2024-08-28 17:21:02 字数 90 浏览 2 评论 0原文

我想验证应该只接受“字母”和“。”的文本框。和 ”/”。

如何使用 jquery 插件做到这一点?

提前致谢。jquery vlidt

I want to validate the textbox which should accept only "letters" and "." and "/".

how to do this using jquery plugin?

thanks in advance.jquery vlidt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月棠 2024-09-04 17:21:02

您需要扩展验证插件以使用正则表达式,如本文中所述:StackOverflow

    $.validator.addMethod( 
        "regex", 
        function(value, element, regexp) { 
            var check = false; 
            var re = new RegExp(regexp); 
            return this.optional(element) || re.test(value); 
        }, 
        "Please check your input." 
); 

$("Textbox").rules("add", { regex: "^[a-zA-Z./]+" })  - I think this reg expression is right...?

对于您的具体示例,可以找到正则表达式列表 此处

You will need to extend the validation plugin to use a regular expression as discussed in this post here: StackOverflow

    $.validator.addMethod( 
        "regex", 
        function(value, element, regexp) { 
            var check = false; 
            var re = new RegExp(regexp); 
            return this.optional(element) || re.test(value); 
        }, 
        "Please check your input." 
); 

$("Textbox").rules("add", { regex: "^[a-zA-Z./]+" })  - I think this reg expression is right...?

And for your specific example, a list of regular expressions can be found here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文