簡體   English   中英

preg_match問題

[英]problem with preg_match

我必須驗證激光信用卡。 該卡以6304、6706、6709、6771開頭,長度為16或19位數字。 我有一個preg_match,我要傳遞的卡號是6706開頭,有19位數字,但它返回false。

    // Laser (Laser) P: 6304, 6706, 6709, 6771 L: 16,19
    } elseif (preg_match('/^(?:[6304|6706|6709|6771])\d{12,15}$/', $number)) {
        $type = 'laser';
/^6(?:304|706|709|771)(?:\d{12}|\d{15})$/

細分:

/^                        # start of line
   6(?:304|706|709|771)     # your 6xxx codes
   (?:\d{12}|\d{15})        # 12 (16-4) or 15 (19-4) more numbers
$/                        # end of pattern

指出您的錯誤:

(?:[6304 | 6706 | 6709 | 6771])

請記住[]是CLASS。 這意味着要查找括號內的所有這些字符。 如果您要選擇“ /”或“或”,則需要使用group ()

已修復,其外觀應為(?:6304|6706|6709|6771)

\\ d {12,15}

我的理解是,您需要固定長度的數字,而不是可變的數字。 您的量詞是說可以再增加12、13,...,15個數字。 我們只想要12或15。

暫無
暫無

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

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