You can have it without using triggers, you can try it by Roll-Up summary that will going to count records, and can able to add a validation rule on account like:
ContactCount__c = 0 && PRIORVALUE(ContactCount__c) > 0
I hope this will help.
Want to become a salesforce expert? join salesforce lightning training now!!