@is_12 

you will require 2 onChange client scripts i.e. 1 for account and 1 for contact name

both the client script will have similar scripts and will show error on respective field/variable when validation fails.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader