JavaScript/jQuery VIN Validator

前端 未结 2 458
[愿得一人]
[愿得一人] 2021-01-05 03:01

Has anyone ever created a VIN Validator? I am trying to create a textbox where the user will enter in a Vehicle Identification Number and then JS/jQuery will validate if its

2条回答
  •  花落未央
    2021-01-05 04:01

    Here's a client-side solution using Regular Expressions.

    $(function() {
      $("#vin").on("keyup blur", function() {
        if (validateVin($("#vin").val()))
          $("#result").html("That's a VIN");
        else
          $("#result").html("Not a VIN");
      }).trigger("blur");
    });
      
    function validateVin(vin) {
      var re = new RegExp("^[A-HJ-NPR-Z\\d]{8}[\\dX][A-HJ-NPR-Z\\d]{2}\\d{6}$");
      return vin.match(re);
    }
    
    
    
    

提交回复
热议问题