1
13693261870
2022-09-16 06df9667ad1465622bf0e423dc3840ef9f93c725
1
2
3
4
5
6
7
8
9
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
 * Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
 */
$.validator.addMethod( "cifES", function( value ) {
    "use strict";
 
    var num = [],
        controlDigit, sum, i, count, tmp, secondDigit;
 
    value = value.toUpperCase();
 
    // Quick format test
    if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {
        return false;
    }
 
    for ( i = 0; i < 9; i++ ) {
        num[ i ] = parseInt( value.charAt( i ), 10 );
    }
 
    // Algorithm for checking CIF codes
    sum = num[ 2 ] + num[ 4 ] + num[ 6 ];
    for ( count = 1; count < 8; count += 2 ) {
        tmp = ( 2 * num[ count ] ).toString();
        secondDigit = tmp.charAt( 1 );
 
        sum += parseInt( tmp.charAt( 0 ), 10 ) + ( secondDigit === "" ? 0 : parseInt( secondDigit, 10 ) );
    }
 
    /* The first (position 1) is a letter following the following criteria:
     *    A. Corporations
     *    B. LLCs
     *    C. General partnerships
     *    D. Companies limited partnerships
     *    E. Communities of goods
     *    F. Cooperative Societies
     *    G. Associations
     *    H. Communities of homeowners in horizontal property regime
     *    J. Civil Societies
     *    K. Old format
     *    L. Old format
     *    M. Old format
     *    N. Nonresident entities
     *    P. Local authorities
     *    Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions
     *    R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)
     *    S. Organs of State Administration and regions
     *    V. Agrarian Transformation
     *    W. Permanent establishments of non-resident in Spain
     */
    if ( /^[ABCDEFGHJNPQRSUVW]{1}/.test( value ) ) {
        sum += "";
        controlDigit = 10 - parseInt( sum.charAt( sum.length - 1 ), 10 );
        value += controlDigit;
        return ( num[ 8 ].toString() === String.fromCharCode( 64 + controlDigit ) || num[ 8 ].toString() === value.charAt( value.length - 1 ) );
    }
 
    return false;
 
}, "Please specify a valid CIF number." );