我需要一种模式来验证输入字段的格式如下。
1st char: a, b, c, or d
2nd: 0-9
third: 0-9
4th: 0-9 (optional char)
valid example: a939, c321, d11, c32
invalid: aa939, c1
preg_match('/^[DSFP][0-9]/', $data) // doesn't work :(
您的正则表达式应为:
/^[abcd]\d{2,3}$/i
解释:
^ -- matches line start
[abcd] -- matches one of literal characters a, b, c, d
\d{2,3} -- matches 2 or 3 digits
$ -- matches line end
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句