Regular Expressions 101

Community Patterns

1...34567...902

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
^((B|b)([0-9]{7}|[0-9]{6}|[0-9]{5}|[0-9]{4}|[0-9]{3}|[0-9]{2}|[0-9]{1}))*$
/

Description

This regex will match an input string of the letter B (or b) followed up by to 7 numerical digits. It will fail if any letter/number/symbol is used other than B (or b) and more than 7 numbers are entered after B (or b). This is simple and was useful for validating a Court Case ID number for users after being entered into a textbox.

Submitted by Alan Armbrust - 8 years ago