In: Computer Science
A vehicle’s VIN is very important for any and all paperwork, such as lease agreements, insurance details, servicing schedule etc. However it is easy to mistype a long sequence of characters, and so we’d like to add some validation to ensure that anything entered into this field at least has the right format to be a VIN.
• A VIN is a string of exactly 17 characters
• Each character in a VIN is a digit or an uppercase letter
• A VIN can contain any of the digits 0 to 9
• A VIN can contain any uppercase letter except I, O and Q
• The 9th character of a VIN is either a digit from 0 to 9 or the letter X.
(These are all true facts about a VIN, but in real VINs the 9th character acts a check digit and must satisfy an equation involving the other 16 characters.).
Now, the code needed to be written in SQLITE to check a 17-digit VIN can be very cumbersome. So instead, we’ll use a simplified version of a VIN for this project, which is defined as follows:
• A VIN is a string of exactly 5 characters
• Each character in a VIN is a digit or an uppercase letter
• A VIN can contain any of the digits 0 to 9 6
• A VIN can contain any uppercase letter except I, O and Q
• The 3rd character of a VIN is either a digit from 0 to 9 or the letter X
I am using RegularExpression for validating VIN
public class Vehicle
{
[RegularExpression("[A-HJ-NPR-Z0-9]{13}[0-9]{4}", ErrorMessage =
"Invalid Vehicle Identification Number Format.")]
public string VIN { get; set; }
}
VIN usually consist of 17 characters.
The very first letter or number of the VIN tells you in what region of the world your vehicle was made.
The second letter or number, in combination with the first letter or number in the VIN, tells you in what country the car or truck was made.
The third number or letter is used by the vehicle manfacturer to identify what kind of vehicle it is.
The 4th 5th 6th 7th 8th characters, you can find out the vehicle model, engine type, body style.
The 9th character is the VIN check digit where you can use math to figure out if it is a correct VIN.
The 10th letter or number of the VIN tells you the model year of the vehicle.
The 11th 12th 13th 14th 15th 16th characters is where the auto manufacturers enter unique information about the particular vehicle the VIN belongs to.
Hope this answers your questions, please leave a upvote if you find this helpful.