Trying to validate a form that contains information about a car. Have all the validation completed apart from part for the registration number, the format it has to be entered is two letters, a hyphen, last two digits of the year its from, another hyphen, then 3 letters. eg GT-00-TRE. I have the validation for the last three letters, however not sure on how to check theat there are only two letters before the first hyphen and that after the first hyphen there are two numbers. The code i have for this part is:
// get length of reg number entered
var len = theForm.registrationNumber.value.length;
// get position of last occurance of '-'
var lastDotPos = theForm.registrationNumber.value.lastIndexOf('-');
// get number of chars after last '.'
var numCharsAfterLastDot=len-lastDotPos;
// need to decrement numCharsAfterLastDot as lastIndexOf counts from 0
numCharsAfterLastDot--;
// check if a . character appears less than 2 or more than 3 characters from the end of the email
if (numCharsAfterLastDot<3)
{
errorStr = errorStr + "\nInvalid registration number - less than 3 characters following last -";
isCorrect=false;
}
if (numCharsAfterLastDot>4)
{
errorStr = errorStr + "\nInvalid reg number - more than 4 characters following last -";
isCorrect=false;
}