Uk Driver License Number Example

Active4 years, 5 months ago

I'm trying to validate a drivers license for a form that i am making.I was trying to use a single regex.

  1. Max length 9 characters
  2. Alphanumeric characters only
  3. Must have at least 4 numeric characters
  4. Must have no more than 2 alphabetic characters
  5. The third and fourth character must be numeric

I'm new at regex I'm googling trying to work it out. Help with this would be appreciated.

  1. Driving Licence Number. What do the numbers and letters in my licence number mean? Here is a guide to the UK driving licence number format. Digit 1–5: The first five characters of the surname (extra 9's added for names shorter than 5 letters).
  2. The driver's license number is the same as the person's Tax ID number. El Salvador licenses (as well as vehicle circulation cards) contain a chip which can be read by putting the card in a chip reader. There are several categories of drivers' licenses in El Salvador.

State Driver’s License Formats State License Format Alabama 1-8Numeric Alaska 1-7Numeric Arizona 1 Alpha + 8 Numeric OR 9 Numeric Arkansas 4-9Numeric California 1Alpha+7Numeric.

Ian Boyd
129k202 gold badges724 silver badges1041 bronze badges
NorthNorth

3 Answers

Trying to solve this with just one regex is probably a little hard as you need to keep track of multiple things. I'd suggest you try validating each of the properties separately (unless it makes sense to do otherwise).

Uk Driver License Number Example List

For example you can verify the first and second properties easily by checking for a character class including all alphanumeric characters and a quantifier which tells that it should be present at most 9 times:

The anchors^ and $ ensure that this will, in fact, match the entire string and not just a part of it. As Marc Gravell pointed out the string 'aaaaa' will match the expression 'a{3}' because it can match partially as well.

Checking the fifth property can be done similarly, although this time we don't care about the rest:

Here the ^ character is an anchor for the start of the string, the dot (.) is a placeholder for an arbitrary character and we're checking for the third and fourth character being numeric again with a character class and a repetition quantifier.

Properties three and four are probably easiest validated by iterating through the string and keeping counters as you go along.

EDIT:Marc Gravell has a very nice solution for those two cases with regular expressions as well. Didn't think of those.

If you absolutely need to do this in one regular expression this will be a bit work (and probably neither faster nor more readable). Basically I'd start with enumerating all possible options such a string could look like. I am using a here as placeholder for an alphabetic characters and 1 as a placeholder for a number.

We need at least four characters (3) and the third and fourth are always fixed as numbers. For four-character strings this leaves us with only one option:

Five-character strings may introduce a letter, though, with different placements:

and, as before, the all-numeric variant:

Going on like this you can probably create special rules for each case (basically I'd divide this into 'no letter', 'one letter' and 'two letters' and enumerate the different patterns for that. You can then string together all patterns with the pipe () character which is used as an alternative in regular expressions.

I hope you have as much fun playing it as I did building it!!!-kangeroo123Have you ever wanted to visit the world of Harry Potter? Well now you can! Enjoy UPDATE 4 of The Harry Potter Adventure! In The Harry Potter Adventure! In this world you will get to start at one of three locations: number 4 Privet Drive, The Burrow, or Hermione's house. Hogwarts minecraft xbox one download.

Community
JoeyJoey
278k67 gold badges592 silver badges621 bronze badges

Does it have to be a single regex? I'd keep things simple by keeping them separate:

Marc Gravell

Uk Driver License Requirements

HampshireMarc GravellDriver

Uk Driver License Number Example Samples

824k213 gold badges2227 silver badges2624 bronze badges

Uk Driver License Number Format

James FlemingJames Fleming

Uk Driver License Example

2,1792 gold badges22 silver badges35 bronze badges

Uk Driver License Number Example 2019 Date

Not the answer you're looking for? Browse other questions tagged c#regex or ask your own question.

Comments are closed.