Vehicle Number Plate Validation Check

craignet

New Member
Joined
Aug 4, 2012
Messages
11
Hi All,

I'm looking for a function which will check if the cell value is a valid UK registration number plate format.

True if it is, False if it isn't.

I've tried myself and had a look around but am unable to find a solution to my problem.

If also possible, if false, to make to necessary amendments to make it a valid format...ie If some lower case values, make them upper case, if there is a space entered, remove it, if a O is entered instead of a 0, correct it and show the corrected value when the function is run. For all that it can't do that with, then leave as False.

I understand the second part may not be possible, even if someone can help with just identifying whether or not the value is a valid format, I would be very grateful. I have something similar which does this for UK postcodes, but am hitting a brick wall trying to do the same for UK registration number plates.

Any help much appreciated.

Craig</SPAN>
 
Here's a tighter option to reduce false positives:
Code:
Function IsValid(s As String) As Boolean
  Static RX As Object
  Dim tests, x As Long
  
  tests = Array( _
     "^[A-Z]{2}(5[1-9]|0[2-9]|6[0-9]|1[0-9])[A-Z]{3}$", _
     "^[A-HJ-NP-Y]\d{1,3}[A-Z]{3}$", _
     "^[A-Z]{3}\d{1,3}[A-HJ-NP-Y]$", _
     "^(?:[A-Z]{1,2}\d{1,4}|[A-Z]{3}\d{1,3})$", _
     "^(?:\d{1,4}[A-Z]{1,2}|\d{1,3}[A-Z]{3})$")
     
  
  If RX Is Nothing Then
    Set RX = CreateObject("VBScript.RegExp")
  End If
  For x = LBound(tests) To UBound(tests)
    RX.Pattern = tests(x)
    If RX.test(s) Then
        IsValid = True
        Exit Function
    End If
  Next x




End Function

Hello

I appreciate this thread is a tad old, however I have identified a further valid VRM which is three alpha characters, including Z, and then either three or four numbers, such as WEZ1234

What would need to be changed in order to ensure this is marked as Valid?

Thank you in advance...
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top