簡體   English   中英

空格正則表達式asp.net

[英]Whitespace Regular expression 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.

我如何創建可以滿足我所有要求的調節器?

這是您的問題. 匹配一切

做這個

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

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


要么

^\\w{6,10}$

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

Some1.Kill.The.DJ答案很好,但是對於您個人的知識,您還可以使用以下方法:

^\S{6,10}$

\\S以與[^\\s]相同的方式匹配除space以外的所有字符

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM