-1

This bit of regex helps me validate IBAN numbers but it doesnt allow spaces. Some people add spaces to their IBAN numbers, which messes with the validation.

How can i make it so that it allows spaces anywhere the string?

if (preg_match('/^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/', $iban)) {
  // do something
}
ndnenkov
  • 35,425
  • 9
  • 72
  • 104
Daniel B
  • 72
  • 1
  • 9

1 Answers1

1
if (preg_match('/^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/', str_replace(' ', '', $iban))) {
  // do something
}
ndnenkov
  • 35,425
  • 9
  • 72
  • 104