Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added NIF, NIE and CIF Spanish documents numbers validation
* Added some translations to /localization * Added test suite Fixes gh-830
- Loading branch information
Showing
11 changed files
with
241 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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 | ||
*/ | ||
jQuery.validator.addMethod( "cifES", function ( value, element ) { | ||
"use strict"; | ||
|
||
var sum, | ||
num = [], | ||
controlDigit; | ||
|
||
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 ( var 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 ( var count = 1; count < 8; count += 2 ) { | ||
var 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." ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain | ||
*/ | ||
jQuery.validator.addMethod( "nieES", function ( value, element ) { | ||
"use strict"; | ||
|
||
value = value.toUpperCase(); | ||
|
||
// Basic 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; | ||
} | ||
|
||
// Test NIE | ||
//T | ||
if ( /^[T]{1}/.test( value ) ) { | ||
return ( value[ 8 ] === /^[T]{1}[A-Z0-9]{8}$/.test( value ) ); | ||
} | ||
|
||
//XYZ | ||
if ( /^[XYZ]{1}/.test( value ) ) { | ||
return ( | ||
value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt( | ||
value.replace( 'X', '0' ) | ||
.replace( 'Y', '1' ) | ||
.replace( 'Z', '2' ) | ||
.substring( 0, 8 ) % 23 | ||
) | ||
); | ||
} | ||
|
||
return false; | ||
|
||
}, "Please specify a valid NIE number." ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals | ||
*/ | ||
jQuery.validator.addMethod( "nifES", function ( value, element ) { | ||
"use strict"; | ||
|
||
value = value.toUpperCase(); | ||
|
||
// Basic 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; | ||
} | ||
|
||
// Test NIF | ||
if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) { | ||
return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) ); | ||
} | ||
// Test specials NIF (starts with K, L or M) | ||
if ( /^[KLM]{1}/.test( value ) ) { | ||
return ( value[ 8 ] === String.fromCharCode( 64 ) ); | ||
} | ||
|
||
return false; | ||
|
||
}, "Please specify a valid NIF number." ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters