When handling Salesforce IDs in scripts, prefer the 18-character form for storage and comparisons since the trailing 3 characters are a case-safety checksum. Validate with a format regex first, then verify the checksum on 18-char IDs before treating one as real.

Context: Stack Overflow #9742913 (accepted answer, 51 votes): the asker wanted to validate Salesforce IDs and noticed they come in 15 and 18 character forms. The accepted answer (51 votes) explains the two levels: a regex for the 15 or 18 character alphanumeric format, plus a 3-character checksum appended to the 18-char form that can actually verify the ID. The checksum exists because 15-char IDs are case-sensitive and lose information when moved through case-insensitive systems, so the 18-char form is the safe one to store and compare.