0

I found a regex example for international iban numbers but the is returning false. What am I doing wrong.

Apex

public static Boolean validateIban(String iban) {
        Boolean res = true;
        String ibanRegex = '^([A-Z]{2}[ '+'\\'+'-]?[0-9]{2})(?=(?:[ '+'\\'+'-]?[A-Z0-9]){9,30}$)((?:[ '+'\\'+'-]?[A-Z0-9]{3,5}){2,7})([ '+'\\'+'-]?[A-Z0-9]{1,3})?$'; 
        Pattern MyPattern = Pattern.compile(ibanRegex);
        if(iban!=null){
        Matcher MyMatcher = MyPattern.matcher(iban);
        if (!MyMatcher.matches()) 
            res = false;
        }
        return res; 
    }

Tested with: 'NL50RABO9737375777'

3

1 Answer 1

1

Please check out this code.You forgot to put braces

public static Boolean validateIbanNumber(String iban) {

    Boolean res = true;
    String ibanRegex = '^([A-Z]{2}[ '+'\\'+'-]?[0-9]{2})(?=(?:[ '+'\\'+'-]?[A-Z0-9]){9,30}$)((?:[ '+'\\'+'-]?[A-Z0-9]{3,5}){2,7})([ '+'\\'+'-]?[A-Z0-9]{1,3})?$'; 
    Pattern MyPattern = Pattern.compile(ibanRegex);
    if(iban!=null){
        Matcher MyMatcher = MyPattern.matcher(iban);
        if (!MyMatcher.matches()) 
        {

            res = false;
        }

    } 
    return res; 
}
1
  • Thanks for pointing that out, should have seen that.
    – Thomas
    Jan 7, 2020 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.