Use a Transaction Security Policy on the LoginAs event to block ...

Short answer Use the built-in CASESAFEID() function in Salesforce formulas to ...