简体   繁体   English

jQuery Regex Check:没有最小长度?

[英]jQuery Regex Check: No minimum length?

this is my code: 这是我的代码:

<input type="text" id="Desc" placeholder="Beschreibung (Optional)'"  pattern="^[a-zA-Z\wäöüÄÖÜß\- ][a-zA-Z0-9\wäöüÄÖÜß\- ][\w-.,@&amp;(){}\[\]:;!?\wäöüÄÖÜß\- ]{,150}$" />            

What is should do: ignore when field is empty (no minimum chars) 该做什么:当字段为空时忽略(无最小字符)

But it doesnt work... 但这不起作用...

What am I doing wrong? 我究竟做错了什么?

DoJoChi 道奇

尝试以下方法: pattern="(^[a-zA-Z\\wäöüÄÖÜß\\- ][a-zA-Z0-9\\wäöüÄÖÜß\\- ][\\w-.,@&amp;(){}\\[\\]:;!?\\wäöüÄÖÜß\\- ]{,150}$)?"

Try this: 尝试这个:

<input type="text" id="Desc" placeholder="Beschreibung (Optional)'"  pattern="^[a-zA-Z\wäöüÄÖÜß\- ][a-zA-Z0-9\wäöüÄÖÜß\- ][\w.,@&amp;(){}\[\]:;!?\wäöüÄÖÜß\- ]{5,150}$" />

The problem where first of all w- doesnt do anything, use w+ or w? 所有W-犯规的第一个做任何事情,这个问题用W +W? or only w Second problem {,150} isnt anything use {10,150} which means if it is minimum 10 chars. 或仅使用w第二个问题{,150}不能使用{10,150} ,这意味着至少10个字符。

Copy the regex and pase it to http://regexpal.com/ and you can try it out. 复制正则表达式并将其定位到http://regexpal.com/ ,您可以尝试一下。 Hope this helps you out. 希望这可以帮助你。

It seems you forgot to put brackets and a ? 看来您忘了加上方括号和? to make the whole regex optional. 使整个正则表达式为可选。 I'm also pretty sure {,150} isn't a valid syntax. 我也很确定{,150}不是有效的语法。 It should be {x,150} where x is a number between 0 and 149. 它应该是{x,150} ,其中x是0到149之间的数字。

So, in the end, your regular expression should be something like: 因此,最后,您的正则表达式应类似于:

^([a-zA-Z\wäöüÄÖÜß\- ][a-zA-Z0-9\wäöüÄÖÜß\- ][\w-.,@&amp;(){}\[\]:;!?\wäöüÄÖÜß\- ]{1,150})?$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM