Guide
SWIFT/BIC Codes for Developers
Learn SWIFT/BIC code structure for international banking integrations. Master bank verification, payment system integration, compliance requirements, and automated validation in your applications.
Pavel Volkov
Aug 30, 2025
2 min read
# SWIFT/BIC Codes: Complete Developer Guide for Banking Integration
SWIFT/BIC codes are essential identifiers for international banking and financial transactions. This comprehensive guide covers everything developers need to know about implementing SWIFT code functionality in financial applications.
## Understanding SWIFT/BIC Code Structure
SWIFT codes consist of 8-11 characters with a specific format: **BBBBCCLL[XXX]**
- **BBBB**: Bank code (4 letters)
- **CC**: Country code (2 letters, ISO 3166-1)
- **LL**: Location code (2 characters)
- **XXX**: Branch code (optional, 3 characters)
## Implementing SWIFT Code Validation
### PHP Validation Class
```php
class SwiftCodeValidator
{
private const PATTERN = "/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/";
private array $countryCodes = [
"US", "GB", "DE", "FR", "JP", "CA", "AU", "CH", "NL", "SG"
];
public function validate(string $swift): ValidationResult
{
$swift = strtoupper(trim($swift));
if (!preg_match(self::PATTERN, $swift)) {
return new ValidationResult(false, "Invalid SWIFT code format");
}
if (strlen($swift) !== 8 && strlen($swift) !== 11) {
return new ValidationResult(false, "SWIFT code must be 8 or 11 characters");
}
$countryCode = substr($swift, 4, 2);
if (!in_array($countryCode, $this->countryCodes)) {
return new ValidationResult(false, "Invalid country code: {$countryCode}");
}
return new ValidationResult(true, "Valid SWIFT code");
}
public function extractComponents(string $swift): array
{
$swift = strtoupper(trim($swift));
return [
"bank_code" => substr($swift, 0, 4),
"country_code" => substr($swift, 4, 2),
"location_code" => substr($swift, 6, 2),
"branch_code" => strlen($swift) === 11 ? substr($swift, 8, 3) : null,
"is_primary" => strlen($swift) === 8 || substr($swift, 8, 3) === "XXX"
];
}
}
```
This comprehensive guide provides the foundation for implementing SWIFT/BIC code functionality in financial applications, covering validation, processing, compliance, and testing aspects essential for international banking operations.
Last updated: Aug 30, 2025