0
preg_match("/(11|10|12)([*0-9]+)/i", "11*&!@#")

上は私が試したものです。

私の要件は合計6文字です。

10****   
102***
1023**
10234*
102345

最初の 2 文字は 10 または 11 または 12 のいずれかで、残りの 4 文字は上記のパターンのようにする必要があります。

どうすれば達成できますか?

4

3 に答える 3

7
1[0-2][0-9*]{4}

This should met your requirements:

  • 1 at the begining
  • then 0 or 1 or 2
  • then a digit or *, four times

EDIT

To avoid inputs like 102**5 you can do the pattern more complex:

1[0-2](([*]{4})|([0-9][*]{3})|([0-9]{2}[*]{2})|([0-9]{3}[*])|([0-9]{4}))
于 2012-12-27T07:13:42.167 に答える
3

Like this:

#(10|11|12)([0-9]{4})#

Outputs:

enter image description here

于 2012-12-27T07:13:35.863 に答える