I am building a validation for testing to make sure that a correct part number has been entered. Each part begins with MR in CAPS followed by a [SPACE] followed three numbers. e.g. ( MR 123 )
The problem is if i can not seem to figure out how to validate this using jquery.
The part number always begins with MR.
var type = $("input#type").val();
// Check a that a tank type has been entered.
if( type.length < 5 && type.not().contain("MR")){
$("#error_upload").html("Please enter the tank number in a format MR XXX.");
$("#type").css({borderColor:'red'}).focus();
$("name,#file").css({borderColor:'#ccc'});
return false;
}
Any help would be great.
I would suggest using regex.
Basically, it looks for MR, then a space (
\s), then 3 numbers ([0-9]{3}). If anything else shows up, it will return false.