[Solved] Regular expression for one Alphabet and many numbers


A regular expression to validate if a string starts with a single letter A-Z in any case and has 1 or more digits and nothing else is: ^[A-Za-z]\d+$

Explanation:

^ … beginning of string (or beginning of line in other context).

[A-Za-z] … a character class definition for a single character (no multiplier appended) matching a letter in range A-Z in any case. \w cannot be used as it matches also an underscore and letters from other languages as for example German umlauts.

\d … a digit which is equal the expression [0-9].

+ … previous expression (any digit) 1 or more times.

$ … end of string (or end of line in other context).

Be careful with a regular expression containing a backslash as used here for \d put into a string as the backslash character is in many programming/scripting languages also the escape character inside strings and must be therefore often escaped with one more backslash, i.e. "^[A-Za-z]\\d+$"

solved Regular expression for one Alphabet and many numbers