validation check for monica

by Jason Crowther

JavaScript

var test = "123456786";

var result = test.match( /(.{8})(.).*/ );

// result is null if no match
// if match:
// result[0] is entire string
// result[1] is first sub match
// result[2] is second sub match
// etc.

if(result == null) {
    alert("Gross match error");   
} else {
     var result2 = result[2].match( /^[0-9xX]$/ );
    
    if(result2) {
         alert("Check digit ok");   
    } else {
        alert("Check digit ("+result[2]+") is not a number or X.");
    }
}