Does anyone know any Vehicle Identification Number
(wiki) validation code written in PHP? I just need to check if the entered vin number is correct or not?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Thanks to all for the algorithm etc. which I see is on Wikipedia. This is the version I put together based on the comments above. Note, there are problems with the versions above, for ex this 00000000000354888 returns OK for a vin. I took what was above and added an option to check year first if <1980, assume it isn't a 17digit real vin (have to), and also if there are sequences of a single character, assume invalid. This is good enough for my needs as I am comparing against values that are filled with 0s if not 17 in length. Also I know the year value so if I check that I can speed up the code by skipping the vin check (yes I could have put that in before the function) lol bye!.
TESTING :
It's "VIN." "VIN Number" = "Vehicle Identification Number Number," which doesn't make sense.
You can see a definition of the structure of VINs here:
http://en.wikipedia.org/wiki/Vehicle_identification_number
And you can work from there, or you can grab this script here:
http://www.geekpedia.com/code29_Check-if-VIN-number-is-valid.html
Here is an improved version of the function posted by jordan:
Here's something I wrote up real quick using the example in the wikipedia article.
Not guaranteed perfect or bug free or super efficient, but should provide you with a solid starting point:
Note: I included the edits provided by Confluence below, making the procedure slightly more succinct.
Note: there is a small percent error with verifying VINs because of the nature of the checksum:
Also note:
11111111111111111
will validate against the procedure above. Whether or not you want to check for that is up to you:reference: http://en.wikipedia.org/wiki/Vehicle_identification_number#Check_digit_calculation
Here's a version of the code by jordan ported to Javascript, hope it's helpful to someone...
I recently had to write a VIN validation class with PHP. I posted my class for everyone to use at: http://dev.strategystar.net/2012/05/validate-vin-checksum-with-php/