-3
rated 0 times
[
0]
[
3]
/ answers: 1 / hits: 90695
/ 11 Years ago, tue, april 2, 2013, 12:00:00
var regex = /[A-Za-z]d[A-Za-z] ?d[A-Za-z]d/;
var match = regex.exec(value);
if (match){
if ( (value.indexOf(-) !== -1 || value.indexOf( ) !== -1 ) && value.length() == 7 ) {
return true;
} else if ( (value.indexOf(-) == -1 || value.indexOf( ) == -1 ) && value.length() == 6 ) {
return true;
}
} else {
return false;
}
The regex looks for the pattern A0A 1B1.
true tests:
A0A 1B1
A0A-1B1
A0A1B1
A0A1B1C << problem child
so I added a check for - or and then a check for length.
Is there a regex, or more efficient method?
More From » regex