- Total length: 18 digits
- Bank code: 3 digits (positions 1-3)
- Branch code: 3 digits (positions 4-6)
- Account number: 11 digits (positions 7-17)
- Check digit: 1 digit (position 18)
- 012: BBVA México bank code
- 345: Branch code (specific branch)
- 67890123456: Account number (11 digits)
- 7: Check digit (calculated using algorithm)
CLABE Validation Algorithm
The CLABE validation algorithm uses a weighted sum calculation to verify account number integrity. Each of the first 17 digits is multiplied by a specific weight (following the pattern 3, 7, 1 repeatedly), then all products are summed. The check digit is calculated as(10 - (sum % 10)) % 10
and must match the 18th digit for the CLABE to be valid:
RFC (Tax ID) Validation
RFC (Registro Federal de Contribuyentes) is Mexico’s tax identification system used alongside CLABE numbers. RFC identifiers come in two distinct formats depending on whether they’re for individuals or businesses:Type | Length | Structure | Pattern | Example |
---|---|---|---|---|
Individual | 13 | 4 letters + 6 digits + 3 alphanumeric characters | ^[A-Z&Ñ]{4}\\d{6}[A-Z\\d]{3}$ | MAGR850920XY1 |
Business | 12 | 3 letters + 6 digits + 3 alphanumeric characters | ^[A-Z&Ñ]{3}\\d{6}[A-Z\\d]{3}$ | ABC850920123 |
Type | Letters Part | Digits Part | Verification Part | Description |
---|---|---|---|---|
Individual | MAGR | 850920 | XY1 | Name-derived letters + birth date + verification code |
Business | ABC | 850920 | 123 | Business name-derived letters + registration date + verification code |
RFC Validation
RFC Validation
This function validates RFC format using regex patterns to ensure proper structure for both individual and business formats:
RFC Type Detection
RFC Type Detection
This function determines whether an RFC belongs to an individual or business based on its length:
Common Validation Patterns
Common validation patterns involve checking the combined length of CLABE and RFC, ensuring they match the expected formats, and validating the check digits for each component. The following functions provide comprehensive validation for Mexican banking data:Complete Banking Data Validation
Complete Banking Data Validation
CLABE Formatting for Display
CLABE Formatting for Display
Account Masking for Security
Account Masking for Security
Error Messages
When validation fails, your application should handle these standardized error codes to provide clear feedback to users. Each error code corresponds to a specific validation failure with localized message support:Error Code | English Message |
---|---|
invalid_clabe | CLABE must be exactly 18 digits with valid checksum |
invalid_clabe_checksum | CLABE checksum is invalid |
invalid_rfc | RFC format is invalid (must be 12-13 alphanumeric characters) |
invalid_institution | Institution code not found in Mexican banking system |
clabe_institution_mismatch | CLABE bank code does not match institution code |
invalid_account_type | Account type must be valid for SPEI transfers |
get_error_message()
function to retrieve localized error messages based on error codes returned by validation functions:
See also
You can find more information about the Mexican banking system in the following guides:- Refer to Institution Codes for Mexican bank codes and account types.
- Read about CLABE Component Extraction to extract components from CLABE numbers.
- See the complete Mexican Banking Reference.