-
-
Save maxmcd/a32a35c0eebcfb77cd005f9dd8958815 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func validateSFID(input string) bool { | |
// https://stackoverflow.com/a/29299786/1333724 | |
if len(input) != 18 { | |
return false | |
} | |
parts := []string{input[0:5], input[5:10], input[10:15]} | |
chars := make([]byte, 3) | |
for j, word := range parts { | |
for i, char := range []byte(word) { | |
// fmt.Println([]byte("AZ")) => [65 90] | |
if char >= 65 && char <= 90 { | |
chars[j] += 1 << uint64(i) | |
} | |
} | |
} | |
for i, c := range chars { | |
if c <= 25 { | |
chars[i] = c + 65 | |
} else { | |
chars[i] = c - 25 + 48 | |
} | |
} | |
if string(chars) == input[15:] { | |
return true | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Warning, as of 10/2022 this does not appear to work for all valid Salesforce IDs. It appears to fail on certain ranges of their semi-sequential ids. We got bit by this. Unfortunately I don't have a working version but if I right one up I will link to it here.