最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery validate - pattern rule is not working as well as custom regex method - Stack Overflow

programmeradmin4浏览0评论

I'm using JQuery Validate plugin to validate if an input contains any spaces or not (No spaces are allowed).

I've tried pattern rule from the additional-methods.js file but it doesn't work at all:

"fos_user_registration_form[plainPassword][first]": {
    required: true,
    minlength: 6,
    pattern: "/^\S*$/"
},

And tried the solution here

"fos_user_registration_form[plainPassword][first]": {
    required: true,
    minlength: 6,
    regex: "/^\S*$/"
},

Bit still it doesn't fire at all when, for example, I type "this is test".

I'm using JQuery Validate plugin to validate if an input contains any spaces or not (No spaces are allowed).

I've tried pattern rule from the additional-methods.js file but it doesn't work at all:

"fos_user_registration_form[plainPassword][first]": {
    required: true,
    minlength: 6,
    pattern: "/^\S*$/"
},

And tried the solution here

"fos_user_registration_form[plainPassword][first]": {
    required: true,
    minlength: 6,
    regex: "/^\S*$/"
},

Bit still it doesn't fire at all when, for example, I type "this is test".

Share Improve this question edited May 23, 2017 at 12:08 CommunityBot 11 silver badge asked Jul 18, 2014 at 19:14 Rafael AdelRafael Adel 7,75927 gold badges79 silver badges119 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

For anyone who faced the same problem. Actually it was a typo from my side.

Simply you'll have to remove the quotations in the regex. Because RegExp constructor accepts it without quotations. So it'll be:

"fos_user_registration_form[plainPassword][first]": {
    required: true,
    minlength: 6,
    pattern: /^\S*$/
},
发布评论

评论列表(0)

  1. 暂无评论