2013-11-22 36 views
1

任何人可以幫助正則表達式十個數字,但不是十零

我需要驗證字符串reg.expresion只包含十個數字

\d{10} 

但不能裝有十個零

+0

這是基本相同[這個問題](http://stackoverflow.com/questions/20144315/regex-creating-an-exception-for-ra-b-c)。一個正則表達式,應該匹配它所做的所有事情,*除了特定的字符串。 –

回答

5

這個怎麼樣:

^(?!0{10})\d{10}$ 

說明:

The regular expression: 

(?-imsx:^(?!0{10})\d{10}$) 

matches as follows: 

NODE      EXPLANATION 
---------------------------------------------------------------------- 
(?-imsx:     group, but do not capture (case-sensitive) 
         (with^and $ matching normally) (with . not 
         matching \n) (matching whitespace and # 
         normally): 
---------------------------------------------------------------------- 
^      the beginning of the string 
---------------------------------------------------------------------- 
    (?!      look ahead to see if there is not: 
---------------------------------------------------------------------- 
    0{10}     '0' (10 times) 
---------------------------------------------------------------------- 
)      end of look-ahead 
---------------------------------------------------------------------- 
    \d{10}     digits (0-9) (10 times) 
---------------------------------------------------------------------- 
    $      before an optional \n, and the end of the 
          string 
---------------------------------------------------------------------- 
)      end of grouping 
---------------------------------------------------------------------- 
+0

感謝您的詳細解答 – Kaiser

+0

@Kaiser:不客氣。 – Toto

相關問題