I managed to get it working using the below code:
//Restrict number of attachments
fd.rendered(function() {
fd.field('AttachImages').validators.push({
name: 'Check Attachment',
error: "Only 6 files are allowed, please remove attachments",
validate: function(value) {
if (fd.field('AttachImages').value.length > 6 ) {
return false;
}
else {
return true;
}
}
});