Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1105001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:33:47+00:00 2026-05-17T01:33:47+00:00

How can I validate a Vehicle Identification Number with PHP? I just need to

  • 0

How can I validate a Vehicle Identification Number with PHP? I just need to check if the entered VIN number is correct or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:33:48+00:00Added an answer on May 17, 2026 at 1:33 am

    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.

    function validate_vin($vin) {
    
        $vin = strtolower($vin);
        if (!preg_match('/^[^\Wioq]{17}$/', $vin)) { 
            return false; 
        }
    
        $weights = array(8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2);
    
        $transliterations = array(
            "a" => 1, "b" => 2, "c" => 3, "d" => 4,
            "e" => 5, "f" => 6, "g" => 7, "h" => 8,
            "j" => 1, "k" => 2, "l" => 3, "m" => 4,
            "n" => 5, "p" => 7, "r" => 9, "s" => 2,
            "t" => 3, "u" => 4, "v" => 5, "w" => 6,
            "x" => 7, "y" => 8, "z" => 9
        );
    
        $sum = 0;
    
        for($i = 0 ; $i < strlen($vin) ; $i++ ) { // loop through characters of VIN
            // add transliterations * weight of their positions to get the sum
            if(!is_numeric($vin{$i})) {
                $sum += $transliterations[$vin{$i}] * $weights[$i];
            } else {
                $sum += $vin{$i} * $weights[$i];
            }
        }
    
        // find checkdigit by taking the mod of the sum
    
        $checkdigit = $sum % 11;
    
        if($checkdigit == 10) { // checkdigit of 10 is represented by "X"
            $checkdigit = "x";
        }
    
        return ($checkdigit == $vin{8});
    }
    

    Note: there is a small percent error with verifying VINs because of the nature of the checksum:

    …a match does not prove the VIN is correct, because there is still a 1 in 11 chance of any two distinct VINs having a matching check digit.

    Also note: 11111111111111111 will validate against the procedure above. Whether or not you want to check for that is up to you:

    Straight-ones (seventeen consecutive ‘1’s) will suffice the check-digit. This is because a value of one, multiplied against 89 (sum of weights), is still 89. And 89 % 11 is 1, the check digit. This is an easy way to test a VIN-check algorithm.

    reference: http://en.wikipedia.org/wiki/Vehicle_identification_number#Check_digit_calculation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I validate that my ASPNET AJAX installation is correct. I have Visual
What is a good regular expression that can validate a text string to make
I'm looking for a plugin for jQuery that can validate as a key is
I'm writing a quick Rails app and was wondering how I can validate the
How can I validate the user input by using scanf. Right now I have
Using the jQuery Validation plugin and AJAX, how can I validate the contents of
I have been seriously disappointed with WPF validation system. Anyway! How can I validate
Can anybody help me to build an XSD file to validate XMLs like these:
I assume that you can't use a JavaScript code snippet to validate if the
Can a single regex be used to valdate urls and match all the parts,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.