Search code examples
regexsalesforce

Validating a Salesforce Id


Is there a way to validate a Salesforce ID, maybe using RegEx? They are normally 15 chars or 18 chars but do they follow a pattern that we can use to check that it's a valid id.


Solution

  • There are two levels of validating salesforce id:

    1. check format using regular expression [a-zA-Z0-9]{15}|[a-zA-Z0-9]{18}
    2. for 18-characted ids you can check the the 3-character checksum: enter image description here

    Code examples provided in comments: