Pakistan Special
Pakistan IBAN Regex
Pakistani banks issue International Bank Account Numbers that are 24 characters long. Each one starts with the country code PK, then two check digits, then a four-letter bank code, and finally sixteen digits for the account. This pattern enforces that exact layout with no spaces, which is how the number is usually entered into online banking and payment forms. It catches common slips such as a missing digit, a lowercase bank code or a foreign IBAN pasted by mistake. It does not compute the check digits, so run the standard mod-97 checksum in code for a stronger test before processing transfers.
Pattern (JavaScript)
/^PK\d{2}[A-Z]{4}\d{16}$/Starts at the start of the line/string, then the text "PK", then exactly 2 digits, then an uppercase letter, exactly 4 times, then exactly 16 digits, then the end of the line/string.
Examples
Matches
- ✓ PK12ABCD0000000000000001
- ✓ PK99BANK1234567890123456
- ✓ PK00TEST0000000000000000
Does not match
- ✗ PK12ABCD000000000000000
- ✗ GB29TEST60161331926819
- ✗ PK12AB120000000000000001
Try it
0 matches (JavaScript engine)
PK12ABCD0000000000000001
PK99BANK1234567890123456
PK00TEST0000000000000000
PK12ABCD000000000000000
GB29TEST60161331926819
PK12AB120000000000000001Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^PK\d{2}[A-Z]{4}\d{16}$/g;
const text = "PK12ABCD0000000000000001";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^PK\d{2}[A-Z]{4}\d{16}$')
text = 'PK12ABCD0000000000000001'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^PK\d{2}[A-Z]{4}\d{16}$/';
$text = 'PK12ABCD0000000000000001';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^PK\\d{2}[A-Z]{4}\\d{16}$");
String text = "PK12ABCD0000000000000001";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^PK\d{2}[A-Z]{4}\d{16}$`)
text := "PK12ABCD0000000000000001"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^PK\d{2}[A-Z]{4}\d{16}$");
var text = "PK12ABCD0000000000000001";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^PK\d{2}[A-Z]{4}\d{16}$").unwrap();
let text = "PK12ABCD0000000000000001";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^PK\d{2}[A-Z]{4}\d{16}$/
text = 'PK12ABCD0000000000000001'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Does this check the IBAN check digits?
- No. The two digits after PK are a mod-97 checksum that needs arithmetic. Compute it in code after the shape passes.
- How do I accept IBANs written in groups of four?
- Remove spaces before testing. IBANs are often printed in groups of four for readability, but the stored value has no spaces.
- What do the four letters mean?
- They are the bank identifier, a short code for the bank that holds the account. The sixteen digits that follow identify the account at that bank.