Skip to content

Commit

Permalink
Add validation method for BIC. Closes gh-743
Browse files Browse the repository at this point in the history
  • Loading branch information
rstaib authored and jzaefferer committed May 14, 2013
1 parent 059dbd4 commit ed51405
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions additional-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ jQuery.validator.addMethod("iban", function(value, element) {
return cRest === 1;
}, "Please specify a valid IBAN");

/**
* BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
*
* BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
*
* BIC definition in detail:
* - First 4 characters - bank code (only letters)
* - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
* - Next 2 characters - location code (letters and digits)
* a. shall not start with '0' or '1'
* b. second character must be a letter ('O' is not allowed) or one of the following digits ('0' for test (therefore not allowed), '1' for passive participant and '2' for active participant)
* - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)
*/
jQuery.validator.addMethod("bic", function(value, element) {
return this.optional( element ) || /^([A-Z]{6}[A-Z2-9]{1}[A-NP-Z1-2]{1})(X{3}|[A-WY-Z0-9]{1}[A-Z0-9]{2})?$/.test( value );
}, "Please specify a valid BIC code");

jQuery.validator.addMethod("dateNL", function(value, element) {
return this.optional(element) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(value);
}, "Please enter a correct date");
Expand Down
28 changes: 28 additions & 0 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,34 @@ test("iban", function() {
ok( method( "GB29 NWBK 6016 1331 9268 19"), "Valid IBAN - GB");
});

/**
* BIC tests (For BIC definition take a look on the implementation itself)
*/
test("bic", function() {
var method = methodTest( "bic" );

ok( !method( "PBNKDEF" ), "Invalid BIC: too short" );
ok( !method( "DEUTDEFFA1" ), "Invalid BIC: disallowed length" );
ok( !method( "PBNKDEFFXXX1" ), "Invalid BIC: too long" );
ok( !method( "1BNKDEFF" ), "Invalid BIC: invalid digit" );
ok( !method( "PBNKDE1F" ), "Invalid BIC: invalid digit" );
ok( !method( "PBNKDEF3" ), "Invalid BIC: invalid digit" );
ok( !method( "PBNKDEFO" ), "Invalid BIC: invalid char" );
ok( !method( "INGDDEFFXAA" ), "Invalid BIC: invalid char" );
ok( !method( "DEUTDEF0" ), "Invalid BIC: invalid digit" );

ok( method( "DEUTDEFF" ), "Valid BIC" );
ok( method( "DEUTDEFFXXX" ), "Valid BIC" );
ok( method( "PBNKDE2F" ), "Valid BIC" );
ok( method( "INGDDEFF101" ), "Valid BIC" );
ok( method( "INGDDEF2134" ), "Valid BIC" );
ok( method( "INGDDE91XXX" ), "Valid BIC" );
ok( method( "INGDDEF2" ), "Valid BIC" );
ok( method( "AAFFFRP1" ), "Valid BIC" );
ok( method( "DEUTDEFFAB1" ), "Valid BIC" );
ok( method( "DEUTDEFFAXX" ), "Valid BIC" );
});

test("postcodeUK", function() {
var method = methodTest("postcodeUK");
ok( method( "AA9A 9AA" ), "Valid postcode" );
Expand Down

0 comments on commit ed51405

Please sign in to comment.