我有一个文本框字段,我想规范输入的内容。
我不希望用户键入超过或少于6-10个字符。这是我的正则表达式,用于限制字符^.{6,10}$我使这部分工作,但我也不希望用户输入空格(Space)。现在,我能够从输入的开头和结尾检测到空格,但如果用户在文本中间键入空格,就不能检测到空格。请参见示例。
" testing" = regulator detects the space in the beginning. regex i use ^[^\s].+[^\s]$
"testing " = regulator detects the space in the end. regex i use here is same as abow
"test ing" = regulator does not detect the space in the middle. tried different regex with no luck.我怎样才能创建一个能做我需要的所有事情的调节器?
发布于 2012-12-05 20:54:36
这是你的.的问题,它匹配所有的东西
执行此操作
^[^\s]{6,10}$
[^\s]可以匹配除space之外的任何字符
或
^\w{6,10}$
\w类似于[\da-zA-Z_]
发布于 2012-12-05 21:19:26
Some1.Kill.The.DJ answers很棒,但对于您的个人知识,您也可以使用以下内容:
^\S{6,10}$\S与[^\s]匹配除space之外的任何字符的方式相同
https://stackoverflow.com/questions/13723689
复制相似问题