Search code examples
phpjavascriptregexformsexpression-web

compose a javascript expression that has one uppecase letter and six numbers


I need to compose a regular JavaScript expression. This expression is based on a serial number The parameters of the expression is this:

One Uppercase Letter at the beginning and the rest of the expression is digits (6)

Example: E234585, C345678, E001234

Thanks for your assistance


Solution

  • Try this expression:

    /^[A-Z]\d{6}$/

    This will match serial numbers in the format you described.

    [A-Z] matches the first uppercase letter, then \d{6} matches the following 6 digits. The anchors (^ and $) ensure the matched string contains only the serial number and nothing else.