I put together a function to help you get where you need to be with your password rules. I will leave it up to you to implement it with your form submission because I am not sure how you plan on implementing that part of your application.
Update: I added code to remove white space from input string before checking the rule conditions.
Reason: If white space is allowed in the input a blank space will count as part of the number checks and return true.
jsfiddle Validate Input with Special Rules
Test HTML:
<div id="results"></div>
Test JavaScript:
/*
The rules to follow are:
The length of code must be 27. Not less, not more.
AA BB C DDDDD EEEEE FFFFFFFFFFFF
AA must be "IT" (uppercase). first 2 characters
BB are numbers (even with the initial zero). 3 & 4 characters
C is a character (uppercase). 5th character
DDDDD are numbers (even with the initial zero). characters 5 - 10
EEEEE are numbers (even with the initial zero). characters 11 - 15
FFFFFFFFFFFF are characters and numbers. It's sufficient that the length is 12.
characters 16 - 27 above
*/
var input = "IT12C1234567891FFFFFFFFFFFF";
validate(input);
function validate(input){//begin function
//remove all of the white space from the input
var input = input.replace(/\s+/g, '');
//test for length
var testLength = input.length === 27;
//2nd and 3rd characters equal IT
var AA = input.substring(0,2) === "IT";
//3rd and 4th characters are numbers
var BB = !isNaN(input.substring(2,4));
//The 5th character is a non numerical capitalized character
var C = isNaN(input.split("")[4]) && input.split("")[4] === input.split("")[4].toUpperCase();
//characters 5 - 10 are numbers
var DDDDD = !isNaN(input.substring(5,10));
//characters 11- 15 are numbers
var EEEEE = !isNaN(input.substring(10,15));
//characters 16 - 27 can be characters and numbers as long as the length is 12
var FFFFFFFFFFFF = input.substring(15,27).length === 12;
//if all the password rules checks return true
if(testLength && AA && BB && C & DDDDD && EEEEE & FFFFFFFFFFFF){//begin if then
//do what you need to do here if the password is valid
}
else{
//let the user know the error here
}
//display test results
document.getElementById("results").innerHTML = testLength + "<br>"
+ AA + "<br>"
+ BB + "<br>"
+ C + "<br>"
+ DDDDD + "<br>"
+ EEEEE + "<br>"
+ FFFFFFFFFFFF + "<br>";
}//end function