There are two levels of validating salesforce id:
- check format using regular expression
[a-zA-Z0-9]{15}|[a-zA-Z0-9]{18} - for 18-characted ids you can check the the 3-character checksum:

Code examples provided in comments:
- C#
- Go
- Javascript
- Ruby
There are two levels of validating salesforce id:
[a-zA-Z0-9]{15}|[a-zA-Z0-9]{18}
Code examples provided in comments: