Search code examples
asp.netexpressionvalidationlicense-key

Convert this in validation expression driver's license numbers


Hi I'm creating a registration page. It has "Enter License Number:" i want to create a validation expression that if the user type a wrong format in that field. The form will not be submitted. It must be corrected before they submitted. I dragged the "Regular Expression Validator" in my website. But they don't have a default expression for license number. I must custom the expression to have my own expression.

Now i only want to know what is the validation expression of this sample license number:

G11-11-004064 -- A Philippines sample driver's license.
LetterNumberNumber - NumberNumber - NumberNumberNumberNumberNumberNumber

Could you convert it?


Solution

  • Here's a regular expression editor. It's aimed towards Ruby but will do for .NET as well:

    I don't know about the detailed specification of the license numbers you#re looking for, but I created a regex based on your example: ^[A-Z]\d{2}-\d{2}-\d{6}$.

    You can modify it here:

    The example explained:

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

    ^ = start of line

    [A-Z] = a single upper case letter

    \d{2} = any number with 2 digits

    \d{6} = any number with 6 digits

    $ = end of line

    If you want to make sure you don't miss lower case letters starting the license use [A-Za-z] instead of [A-Z]

    (Thanks to Paul Sullivan)