2012-12-05 178 views
0

我有一個文本框字段,我想規範什麼輸入英寸空白空間正則表達式asp.net

我不希望用戶輸入更多或更少,然後6-10個字符。這裏是我的限制字符的正則表達式^。{6,10} $我有這部分工作,但我也不希望用戶輸入空格(空格)。現在,我可以檢測輸入開始處和輸入結束處的空白,但是如果用戶在文本中間鍵入空格,則不能。看例子。

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

我該如何創建一個能夠完成我所需要的調節器?

回答

5

它與你的.它匹配一切

做這個

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

[^\s]匹配任意字符,除了space


OR

問題

^\w{6,10}$

\w類似於[\da-zA-Z_]

+0

謝謝,^ [^ \ s] {6,10} $ working像一個魅力 – Mana

2

Some1.Kill.The.DJ答案是偉大的,但你的personnal知識,還可以使用以下命令:

^\S{6,10}$ 

\S比賽除space以外的任何字符[^\s]