Türkiye IBAN verification: Why Regex alone is not enough?
Check the 26-character format of Türkiye IBAN value with regex; Further apply the MOD 97 algorithm to verify the actual check digits.
Checking Türkiye IBAN value only with regex,26 character formatmay say it looks right; It does not indicate that the check digits are correct. For true format validation, it is necessary to first remove spaces and convert to uppercase, then apply the country/length regex and the MOD 97 check together.
This verification shows that the IBAN is mathematically consistent. It does not prove that the account is open, the name of the recipient, or that the IBAN belongs to a specific person.
Türkiye IBAN regex
Türkiye IBANTRIt starts with the country code and contains a total of 26 alphanumeric characters. Since the part after the country code in Turkey consists of numbers, the normalized value can be checked with the following regex:
^TR\d{24}$
Since users can type the IBAN in groups of four, remove the spaces before verifying. It may be safer to explicitly reject different characters like dashes according to your business rule rather than silently accepting them.
If the field can be left blank, separate the must check from the regex. When a non-null value is passed, the format and MOD 97 steps should both work.
How does MOD 97 control work?
- Move the first four characters to the end.
- Convert letters to numbers in the format A=10, B=11 … Z=35.
- Find the remainder when the resulting larger number is divided by 97.
- For valid IBAN the remainder must be 1.
Number exceeds JavaScript's safe integer limit. Therefore all the valueNumberInstead of doing this, proceed with the remaining calculation number by number.
JavaScript IBAN verification example
function validateTrIban(input) {
const iban = String(input).replace(/\s+/g, '').toUpperCase();
if (!/^TR\d{24}$/.test(iban)) return false;
const rearranged = iban.slice(4) + iban.slice(0, 4);
let numeric = '';
for (const char of rearranged) {
numeric += /[A-Z]/.test(char)
? String(char.charCodeAt(0) - 55)
: char;
}
let remainder = 0;
for (const digit of numeric) {
remainder = (remainder * 10 + Number(digit)) % 97;
}
return remainder === 1;
}
The function first checks the country and length, then applies the MOD 97-10 check used in ISO 13616. If your application supports more than one country, keep the IBAN length of each country in a separate table; Do not apply Türkiye regex to every country.
Formatting for user experience
Input can be displayed with spaces, but the canonical value sent to the server and stored in the database must be in uppercase letters without spaces. If the visual formatter distorts the cursor position, format it at input completion or blur.
function formatIban(value) {
return value.replace(/\s+/g, '')
.toUpperCase()
.replace(/(.{4})/g, '$1 ')
.trim();
}
Repeat the frontend check in the backend. Browser verification does not block modified requests.
Separation of security and business rules
A valid check digit does not indicate that the account to be paid belongs to the correct person. In critical transactions such as money transfer, recipient verification mechanisms, user confirmation and transaction summary provided by the bank are also required. Do not write full IBAN values into access logs or error tracking systems; mask when necessary.
It may be useful for the technical team to separate the error message into “IBAN format is incorrect” and “check steps are invalid”. Provide a clear message telling the end user to recheck the value without giving too much detail.
Short guide
Common mistake
^TR\d{24}$accept the IBAN as fully valid when matched; regex does not calculate check digits.