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

  • SEARCH
  • Home
  • 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

I need to use the following regular expression to validate some Asian characters $regexp
How can I validate radio buttons? Because this won't work at all. The radio
hi all i want to know that can we validate a control which is
Imagine a hypothetical object with a number of attributes: pseudocode: class Student { Name:
I'm working on a website where I need to prevent the direct linking to
I have a need to verify a specific hyperlink exists on a given web
Using 1.4.1 against Android under Windows 7. I have a web service being access
I have an excel sheet that is loaded with a dynamic result set of
I would like to clarify what is the proper way to filter user input

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.