Validation for IBAN Regex

0
Hello,   I tried to develop regex for IBAN. My IBAN field must consist of 2 characters (in the beginning), 24 digits and 6 spaces. It should be like TR11 2222 3333 4444 5555 6666 77   I tried a write validation like isMatch($Payment/IBANOnshore, '[A-Za-z][A-Za-z] [0,9][0,9]?[A-Za-z] [0,9][0,9][0,9][0,9]?[A-Za-z] [0,9][0,9][0,9][0,9]?[A-Za-z] [0,9][0,9][0,9][0,9]?[A-Za-z] [0,9][0,9][0,9][0,9]?[A-Za-z] [0,9][0,9][0,9][0,9]?[A-Za-z] [0,9][0,9]')   However, it doesn’t work. What should I do? Thanks in advance.
asked
2 answers
1

Hi,

you can try the below regex

isMatch (yourinputstring,'TR\d{2}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{4}[ ]\d{2}|d{20}')

 

answered
2

As addition to the great answer already provided I want to add that this does not actually validate an IBAN. To validate an IBAN there are some additional algorithms used and other validations. Explanation.

You could build a custom java action using the iban4j lib to verify an iban further:

import org.iban4j.IbanFormat;
import org.iban4j.IbanFormatException;
import org.iban4j.IbanUtil;
import org.iban4j.InvalidCheckDigitException;
import org.iban4j.UnsupportedCountryException;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;

/**
 * IBAN validation based on the iban4j (v3.2.1) library.
 * 
 * Params:
 * IBANString: IBAN that needs to be verified
 * defaultFormat: Default format requires groups of four characters separated by a single space to validate. If false formatting isn't required.
 * 
 * Returns:
 * True if IBAN is valid false if not.
 */
public class VerifyIBAN extends CustomJavaAction<java.lang.Boolean>
{
	private java.lang.String IBANString;
	private java.lang.Boolean defaultFormat;

	public VerifyIBAN(IContext context, java.lang.String IBANString, java.lang.Boolean defaultFormat)
	{
		super(context);
		this.IBANString = IBANString;
		this.defaultFormat = defaultFormat;
	}

	@java.lang.Override
	public java.lang.Boolean executeAction() throws Exception
	{
		// BEGIN USER CODE
		boolean isSucces = true;
		 // try to validate Iban 
		 try {
			 if (this.defaultFormat){
				 IbanUtil.validate(this.IBANString, IbanFormat.Default);
			 } else {
				 IbanUtil.validate(this.IBANString);
			 }
						
		     // valid
		 } catch (IbanFormatException  |
		          InvalidCheckDigitException |
		          UnsupportedCountryException e) {
			 
			 isSucces = false; 
		 }
		 return isSucces;
				
		// END USER CODE
	}

	/**
	 * Returns a string representation of this action
	 * @return a string representation of this action
	 */
	@java.lang.Override
	public java.lang.String toString()
	{
		return "VerifyIBAN";
	}

	// BEGIN EXTRA CODE
	// END EXTRA CODE
}

 

answered