The following regular expression will match:
- AB12 1234 1234 1234 1234
- AB12 1234 1234 1234 1234 1
- AB12 1234 1234 1234 1234 12
but also:
- AB123456789012345678
- AB1234567890123456789
- AB12345678901234567890
^[A-Z]{2}(?:[ ]?[0-9]){18,20}$
If you also need to match IBAN formats by country (BBAN Format), use:
^([A-Z]{2}[ \-]?[0-9]{2})(?=(?:[ \-]?[A-Z0-9]){9,30}$)((?:[ \-]?[A-Z0-9]{3,5}){2,7})([ \-]?[A-Z0-9]{1,3})?$