1. #1
    Ext JS Premium Member anton.dimitrov's Avatar
    Join Date
    Nov 2011
    Location
    The Netherlands
    Posts
    132
    Vote Rating
    5
    anton.dimitrov is on a distinguished road

      0  

    Default Ext.form.field.VTypes - IBAN

    Ext.form.field.VTypes - IBAN


    I checked the forums and couldn't find any IBAN validation so decided to do one by myself.
    The regular expressions are the same as the ones used in ZEND framework for validating IBAN(s) so I presume they work..

    Update: (30.05.2012)
    - fixed a bug with the replacing of characters. The characters must be treated as a regular expressions otherwise only the first occurrence is replaced.


    Code:
    Ext.apply(Ext.form.field.VTypes, {
    
            _ibanregex : {
                'AD' : '^AD[0-9]{2}[0-9]{8}[A-Z0-9]{12}$',
                'AT' : '^AT[0-9]{2}[0-9]{5}[0-9]{11}$',
                'BA' : '^BA[0-9]{2}[0-9]{6}[0-9]{10}$',
                'BE' : '^BE[0-9]{2}[0-9]{3}[0-9]{9}$',
                'BG' : '^BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}$',
                'CH' : '^CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}$',
                'CS' : '^CS[0-9]{2}[0-9]{3}[0-9]{15}$',
                'CY' : '^CY[0-9]{2}[0-9]{8}[A-Z0-9]{16}$',
                'CZ' : '^CZ[0-9]{2}[0-9]{4}[0-9]{16}$',
                'DE' : '^DE[0-9]{2}[0-9]{8}[0-9]{10}$',
                'DK' : '^DK[0-9]{2}[0-9]{4}[0-9]{10}$',
                'EE' : '^EE[0-9]{2}[0-9]{4}[0-9]{12}$',
                'ES' : '^ES[0-9]{2}[0-9]{8}[0-9]{12}$',
                'FR' : '^FR[0-9]{2}[0-9]{10}[A-Z0-9]{13}$',
                'FI' : '^FI[0-9]{2}[0-9]{6}[0-9]{8}$',
                'GB' : '^GB[0-9]{2}[A-Z]{4}[0-9]{14}$',
                'GI' : '^GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}$',
                'GR' : '^GR[0-9]{2}[0-9]{7}[A-Z0-9]{16}$',
                'HR' : '^HR[0-9]{2}[0-9]{7}[0-9]{10}$',
                'HU' : '^HU[0-9]{2}[0-9]{7}[0-9]{1}[0-9]{15}[0-9]{1}$',
                'IE' : '^IE[0-9]{2}[A-Z0-9]{4}[0-9]{6}[0-9]{8}$',
                'IS' : '^IS[0-9]{2}[0-9]{4}[0-9]{18}$',
                'IT' : '^IT[0-9]{2}[A-Z]{1}[0-9]{10}[A-Z0-9]{12}$',
                'LI' : '^LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}$',
                'LU' : '^LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}$',
                'LT' : '^LT[0-9]{2}[0-9]{5}[0-9]{11}$',
                'LV' : '^LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}$',
                'MK' : '^MK[0-9]{2}[A-Z]{3}[A-Z0-9]{10}[0-9]{2}$',
                'MT' : '^MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}$',
                'NL' : '^NL[0-9]{2}[A-Z]{4}[0-9]{10}$',
                'NO' : '^NO[0-9]{2}[0-9]{4}[0-9]{7}$',
                'PL' : '^PL[0-9]{2}[0-9]{8}[0-9]{16}$',
                'PT' : '^PT[0-9]{2}[0-9]{8}[0-9]{13}$',
                'RO' : '^RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}$',
                'SE' : '^SE[0-9]{2}[0-9]{3}[0-9]{17}$',
                'SI' : '^SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}$',
                'SK' : '^SK[0-9]{2}[0-9]{4}[0-9]{16}$',
                'TN' : '^TN[0-9]{2}[0-9]{5}[0-9]{15}$',
                'TR' : '^TR[0-9]{2}[0-9]{5}[A-Z0-9]{17}$'
            },
    
            _formatA: [
                'A',  'B',  'C',  'D',  'E',  'F',  'G',  'H',  'I',  'J',  'K',  'L',  'M',
                'N',  'O',  'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',  'X',  'Y',  'Z'
            ],
    
            _formatN: [
                '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22',
                '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35'
            ],
    
            _ibanUnsupportedRegionText: 'Unsupported IBNA region.',
            _ibanFalseFormatText: 'False format.',
            _ibanCheckFailText: 'IBAN check has failed.',
            _ibanDefultText: 'Unsupported IBNA region.',
            _setIbanError: function(v){
                this.IBANText = v;
            },
            IBANText: 'Unsupported IBNA region',
            IBANMask: /[a-z0-9_]/i,
    
            IBAN:  function(v) {
                v = v.toUpperCase();
                var me = this,
                    preg,
                    format,
                    temp,
                    len,
                    region = v.substr(0,2);
    
                if (!me._ibanregex[region]) {
                    me._setIbanError(me._ibanUnsupportedRegionText);
                    return false;
                }
    
                preg =  new RegExp(me._ibanregex[region]);
                if(!v.match(preg)){
                    me._setIbanError(me._ibanFalseFormatText);
                    return false;
                }
    
                format = v.substr(4) + v.substr(0,4);
                // optimizie...maybe...
                for(var x in me._formatA){
                    if(!!me._formatA[x] && !!me._formatN[x]){
                        var reg = new RegExp(me._formatA[x], 'g');
                        format = format.replace(reg,me._formatN[x]);
                    }
                }
                temp = parseInt(format.charAt(0));
                len  = format.length;
    
                for (var i = 1; i < len; i++) {
                    temp *= 10;
                    temp += parseInt(format.substr(i, 1));
                    temp %= 97;
                }
    
                if (temp != 1) {
                    me._setIbanError(me._ibanCheckFailText);
                    return false;
                }
                return true;
            }
        });
    Last edited by anton.dimitrov; 30 May 2012 at 9:17 AM. Reason: Fixed a bug

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,927
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Thank you for the contribution!

    Regards,
    Scott

  3. #3
    Sencha User
    Join Date
    Feb 2010
    Posts
    353
    Vote Rating
    4
    maneljn is on a distinguished road

      0  

    Default


    Is it possible to modify the vtype to obtain an input mask with an space between each 4 character group ?

    like this

    "ES11 2222 3333 4444 ....."

    Manel
    -------------------
    Manel Juàrez

  4. #4
    Ext JS Premium Member anton.dimitrov's Avatar
    Join Date
    Nov 2011
    Location
    The Netherlands
    Posts
    132
    Vote Rating
    5
    anton.dimitrov is on a distinguished road

      0  

    Default


    It is, but why would you ? This is just a presentation problem and the validation of the IBAN should not be bothered with it. If you need mask regex for input do it on the input component and not on the vtype.
    Just make sure you pass the trimmed string to the IBAN validation.

  5. #5
    Sencha User
    Join Date
    Feb 2010
    Posts
    353
    Vote Rating
    4
    maneljn is on a distinguished road

      0  

    Default


    It's because users that manage iban's with 24 numbers, it's not very confortable to see if you are wrong entering some number, if they are all joined. In groups of 4 characters, is more confortable.

    Manel
    -------------------
    Manel Juàrez

  6. #6
    Sencha User
    Join Date
    Nov 2008
    Posts
    10
    Vote Rating
    0
    ZaDarkSide is on a distinguished road

      0  

    Default


    More complete list of regex for IBAN.
    Didn't test them all out though, so if you find this usefull test them before using them.
    Some assembly required to modify the above function to work with these.

    Code:
            var iban = val.replace(/ /g,'').toUpperCase();
            var countrycode = iban.substring(0,2);
            var bbancountrypatterns = {
                'AL': "\\d{8}[\\dA-Z]{16}",
                'AD': "\\d{8}[\\dA-Z]{12}",
                'AT': "\\d{16}",
                'AZ': "[\\dA-Z]{4}\\d{20}",
                'BE': "\\d{12}",
                'BH': "[A-Z]{4}[\\dA-Z]{14}",
                'BA': "\\d{16}",
                'BR': "\\d{23}[A-Z][\\dA-Z]",
                'BG': "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
                'CR': "\\d{17}",
                'HR': "\\d{17}",
                'CY': "\\d{8}[\\dA-Z]{16}",
                'CZ': "\\d{20}",
                'DK': "\\d{14}",
                'DO': "[A-Z]{4}\\d{20}",
                'EE': "\\d{16}",
                'FO': "\\d{14}",
                'FI': "\\d{14}",
                'FR': "\\d{10}[\\dA-Z]{11}\\d{2}",
                'GE': "[\\dA-Z]{2}\\d{16}",
                'DE': "\\d{18}",
                'GI': "[A-Z]{4}[\\dA-Z]{15}",
                'GR': "\\d{7}[\\dA-Z]{16}",
                'GL': "\\d{14}",
                'GT': "[\\dA-Z]{4}[\\dA-Z]{20}",
                'HU': "\\d{24}",
                'IS': "\\d{22}",
                'IE': "[\\dA-Z]{4}\\d{14}",
                'IL': "\\d{19}",
                'IT': "[A-Z]\\d{10}[\\dA-Z]{12}",
                'KZ': "\\d{3}[\\dA-Z]{13}",
                'KW': "[A-Z]{4}[\\dA-Z]{22}",
                'LV': "[A-Z]{4}[\\dA-Z]{13}",
                'LB': "\\d{4}[\\dA-Z]{20}",
                'LI': "\\d{5}[\\dA-Z]{12}",
                'LT': "\\d{16}",
                'LU': "\\d{3}[\\dA-Z]{13}",
                'MK': "\\d{3}[\\dA-Z]{10}\\d{2}",
                'MT': "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
                'MR': "\\d{23}",
                'MU': "[A-Z]{4}\\d{19}[A-Z]{3}",
                'MC': "\\d{10}[\\dA-Z]{11}\\d{2}",
                'MD': "[\\dA-Z]{2}\\d{18}",
                'ME': "\\d{18}",
                'NL': "[A-Z]{4}\\d{10}",
                'NO': "\\d{11}",
                'PK': "[\\dA-Z]{4}\\d{16}",
                'PS': "[\\dA-Z]{4}\\d{21}",
                'PL': "\\d{24}",
                'PT': "\\d{21}",
                'RO': "[A-Z]{4}[\\dA-Z]{16}",
                'SM': "[A-Z]\\d{10}[\\dA-Z]{12}",
                'SA': "\\d{2}[\\dA-Z]{18}",
                'RS': "\\d{18}",
                'SK': "\\d{20}",
                'SI': "\\d{15}",
                'ES': "\\d{20}",
                'SE': "\\d{20}",
                'CH': "\\d{5}[\\dA-Z]{12}",
                'TN': "\\d{20}",
                'TR': "\\d{5}[\\dA-Z]{17}",
                'AE': "\\d{3}\\d{16}",
                'GB': "[A-Z]{4}\\d{14}",
                'VG': "[\\dA-Z]{4}\\d{16}"
            }
    And the regex testing should look like this:

    Code:
            var bbanpattern = bbancountrypatterns[countrycode];
            // As new countries will start using IBAN in the
            // future, we only check if the countrycode is known.
            // This prevents false negatives, while almost all
            // false positives introduced by this, will be caught
            // by the checksum validation below anyway.
            // Strict checking should return FALSE for unknown
            // countries.
            if (typeof bbanpattern !== 'undefined') {
                var ibanregexp = new RegExp("^[A-Z]{2}\\d{2}" + bbanpattern + "$", "");
                if (!(ibanregexp.test(iban))) {
                    // invalid country specific format
                    return false;
                }
            }

Thread Participants: 3

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi