0

I got this regex expression from REGEXlib and basically it checks to see if it is a valid UK DVLA Number Plate however i cannot get it to work within JavaScript could some one please help as im not the best with regex as it is.

//On change event for the textbox plate text
function setValue(target){
        var platetext = target.value;
        $('#numberplateyellow').empty();
        $('#numberplatewhite').empty();


        var plateregex = /([A-HJ-PR-Y]{2}([0][1-9]|[1-9][0-9])|[A-HJ-PR-Y]{1}([1-9]|[1-2][0-9]|30|31|33|40|44|55|50|60|66|70|77|80|88|90|99|111|121|123|222|321|333|444|555|666|777|888|999|100|200|300|400|500|600|700|800|900))[ ][A-HJ-PR-Z]{3}$/;

        if (document.platebuilder.target.value.search(plateregex)==-1){

        var answer = window.confirm ("Non LEGAL Plate Detected (YES WE WILL SHOW THE AGREE BOX ONCE I HAVE IT FROM TOM) \n\n Do you understand that this is now classed as a show plate ?");

        if (answer) {
        $('#numberplateyellow').append(platetext);
        $('#numberplatewhite').append(platetext);
        }

      }

}

Thanks

4
  • 1
    Need more info. Can you give some example inputs? How is it going wrong? Why are you comparing document.platebuilder.target.value, looks like it is platetext that needs comparing? Commented Mar 8, 2011 at 9:25
  • Are you sure document.platebuilder.target is the same as the function argument target? Commented Mar 8, 2011 at 9:25
  • There are more: regexlib.com/Search.aspx?k=dvla&c=-1&m=-1&ps=20 Commented Mar 8, 2011 at 9:29
  • well i need to check target.value thats the number plate being entered Commented Mar 8, 2011 at 9:29

1 Answer 1

1

You are mixing jQuery and standard script.

Change var platetext = target.value;

to

var platetext = target.val();

and

if (document.platebuilder.target.value.search(plateregex)==-1){

to

if (!platetext.match(plateregex)) {

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.