How to edit an IBAN number in four character groups?

主宰稳场 提交于 2020-01-14 05:32:07

问题


https://en.wikipedia.org/wiki/International_Bank_Account_Number#Practicalities

The IBAN should not contain spaces when transmitted electronically: when printed it is expressed in groups of four characters separated by a single space, the last group being of variable length as shown in the example below:

A typical IBAN looks like this: GR16 0110 1250 0000 0001 2300 695 (taken from the above link).

I want to make it easier for users to enter IBAN numbers. Currently I use a TDBEdit to display the IBAN number and it is stored as characters (without the spaces) in the database.

I know that it is possible to format numbers using TNumericField.DisplayFormat, also there is TMaskEdit, but both aren't terribly useful for this purpose as IBAN is not a number and has different lenghts in different countries.

How to edit an IBAN number in four character groups in a DB control?

PS: I'm not asking for the actual IBAN validation as I already have that figured out.


回答1:


You can use the EditMask property of the IBAN field as this will also work for string fields. A suitable EditMask for IBAN may look like this:

">LL00 aaaa aaaa aaaa aaaa aaaa aaaa aaaa aa;0; "

The first character makes the edit field convert all characters to upper case. The next four entries require two alpha characters followed by two numeric ones. The blanks represent the requested gaps. The lower "a" allows an alphanumeric character but doesn't require it.

The "0" in the second part of the mask will strip any literals (the gap blanks) from the entry stored in the field.

The blank in the third part of the mask makes the gap blanks being displayed as blank.



来源:https://stackoverflow.com/questions/26323452/how-to-edit-an-iban-number-in-four-character-groups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!