简体   繁体   English

空格正则表达式asp.net

[英]Whitespace Regular expression asp.net

I have a textbox field, and i want to regulate whats typed in. 我有一个文本框字段,我想调节输入的内容。

I dont want users to type more or less then 6-10 characters. 我不希望用户键入多于或少于6-10个字符。 here is my regex for limiting the characters ^.{6,10}$ I got this part working, but I also dont want users to type in whitespace(space). 这是我用于限制字符^。{6,10} $的正则表达式。我可以使用此部分,但我也不希望用户键入空格(空格)。 Now i am able to detect whitespace from the beginning of the input and ending of the input, but not if the user types in space in middle of the text. 现在,我能够从输入的开头和输入的结尾检测空白,但是如果用户在文本中间键入空格,则无法检测到空白。 see example. 参见示例。

" 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.

how can i create a regulator which will do all that i require? 我如何创建可以满足我所有要求的调节器?

It is the problem with your . 这是您的问题. which matches everything 匹配一切

Do this 做这个

^[^\\s]{6,10}$

[^\\s] matches any character except space [^\\s]匹配除space以外的任何字符


OR 要么

^\\w{6,10}$

\\w is similar to [\\da-zA-Z_] \\w类似于[\\da-zA-Z_]

Some1.Kill.The.DJ answers is great, but for your personnal knowledge, you can also use the following: Some1.Kill.The.DJ答案很好,但是对于您个人的知识,您还可以使用以下方法:

^\S{6,10}$

\\S matches any characters except space the same way [^\\s] does \\S以与[^\\s]相同的方式匹配除space以外的所有字符

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

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