OK, this is very close if not correct. Just paste it into a file for testing. Enter test numbers and click anyhwere outside the text box to test it.
<html>
<head>
<title>Form test</title>
<script type = "text/javascript">
var nonAlphaNumeric = /[^a-zA-Z0-9]/;
var limitedChars = /[^a-hA-H0-9]/;
var specialChars = /[^def]/;
function A(){
var lgn = document.a.b.value.length;
var txt = document.a.b.value;
var nmb = 151;
if(lgn != 12 && lgn != 15){
alert("Wrong number of chars."

;
return;
}
if(txt.match(nonAlphaNumeric))
{
alert("Non Alpha Numeric Carachter Entered."

;
return;
}
if(lgn == 12){
if(txt.substr(0, 1) == 6){
var t = txt.substr(1, 1);
if(t.match(specialChars)){
alert("Incorrect carachter at position 2."

;
return;
}
}
if(txt.substr(0, 1) != 6){
if(txt.match(limitedChars))
{
alert("Incorrect characters"

;
return;
}
if(txt.substr(4, 1) != "4" && txt.substr(4, 1) != "6"

{
alert("Incorrect carachter at position 5."

;
return;
}
}
}
if(lgn == 15){
if(!(txt.substr(0, 3) == nmb)){
alert("Error in first three carachters"

;
return;
}
if(txt.match(limitedChars))
{
alert("Incorrect characters"

;
return;
}
}
alert("Valid entry."

;
}
</script>
</head>
<body bgcolor="#ffffff">
<form name = "a"><input type = "text" name = "b" onblur = "A()"></form>
</body>
</html>