Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
How to add this UK registration validation to jquery?

In this project I have the following jquery code to validate a form. It works fine, but i'd like it to be more specific by implementing a more thorough validation for UK reg plates. My javascript code is:

function ValidateSspcpForm()
{
  $('#SspcpForm').validate({
    rules: {
      'sspcp[reg]': {
          required: true,
          rangelength: [2, 8],
      },
    messages: {
      'sspcp[reg]': {
        required: "Your car's registration is required in advance, Please input one here.",
        rangelength: "The registration number must be between 2 and 7 characters in length"
      },
    }
  });
}

The method I want to implement is this, it seems to cover everything for UK plates which is perfect for my use case:

(^[A-Z]{2}[0-9]{2}\s?[A-Z]{3}$)|(^[A-Z][0-9]{1,3}[A-Z]{3}$)|(^[A-Z]{3}[0-9]{1,3}[A-Z]$)|(^[0-9]{1,4}[A-Z]{1,2}$)|(^[0-9]{1,3}[A-Z]{1,3}$)|(^[A-Z]{1,2}[0-9]{1,4}$)|(^[A-Z]{1,3}[0-9]{1,3}$)

Any help or ideas would be much appreciated!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Found it. Definitely appears to be quite simple. I'm new to JavaScript, so wasn't aware it would let you outside of the validate method. For anyone else searching, this is how you would implement UK registration plate validation with jquery.validate:

function ValidateSspcpForm()
{
  $.validator.addMethod('Registration', function(value){
    return /^(^[A-Z]{2}[0-9]{2}\s?[A-Z]{3}$)|(^[A-Z][0-9]{1,3}[A-Z]{3}$)|(^[A-Z]{3}[0-9]{1,3}[A-Z]$)|(^[0-9]{1,4}[A-Z]{1,2}$)|(^[0-9]{1,3}[A-Z]{1,3}$)|(^[A-Z]{1,2}[0-9]{1,4}$)|(^[A-Z]{1,3}[0-9]{1,3}$)|(^[A-Z]{1,3}[0-9]{1,4}$)|(^[0-9]{3}[DX]{1}[0-9]{3}$)/.test(value);
  }, 'reg validation has failed');

  $('#SspcpForm').validate({
    rules: {
      'sspcp[reg]': {
          required: true,
          rangelength: [2, 8],
          Registration: true
      },
    },
    messages: {
      'sspcp[reg]': {
        required: "Your car's registration is required in advance, Please input one here.",
        Registration: "This registration number is not a recognised UK plate"
      },
    }
  });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!