Skip to content

[Validator] added BIC (SWIFT-BIC) validation constraint #15519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed

[Validator] added BIC (SWIFT-BIC) validation constraint #15519

wants to merge 9 commits into from

Conversation

mvhirsch
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR symfony/symfony-docs#5623

I've added the BIC validator, because we do often need validation for IBAN and BIC values. Since the IBAN validation was already included into Symfony, I was asking myself: why not contribute my BIC validator to the community? So here we go ...

It depends on ISO 9362 as described on Wikipedia. It validates the structure based on alphabetic/alphanumeric values and the value's length.

Todo-list:

  • submit changes to the documentation

const INVALID_CHARACTERS_ERROR = 2;
const INVALID_BANK_CODE_ERROR = 3;
const INVALID_COUNTRY_CODE_ERROR = 4;
const INVALID_CASE_ERROR = 5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUIDs should be used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I produce some UUIDs?

@stof
Copy link
Member

stof commented Aug 12, 2015

I'm not sure this should be in the core (I'm also not sur ethe IBAN deserves being in core, but it is there already and so needs to stay for BC reasons)

self::INVALID_CASE_ERROR => 'INVALID_CASE_ERROR',
);

public $message = 'This is not a valid Business Identifier Codes (BIC).';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Business Identifier Code (non-plural)

@mvhirsch
Copy link
Contributor Author

Added UUIDs and fixed constraint message (non-plural).

{
// http://formvalidation.io/validators/bic/
return array(
//array('12345678901')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@OskarStark
Copy link
Contributor

i like this feature and think, we have IBAN, so we should provide the BIC Constraint, too.

PR looks good to me

@DracoBlue
Copy link

👍

1 similar comment
@dkeller85
Copy link

👍

@OskarStark
Copy link
Contributor

The [WIP] should be removed from the PR subject @mvhirsch

EDIT: sorry, didn't see the open todo for the docs....

@mvhirsch mvhirsch changed the title [WIP] [Validator] added BIC (SWIFT-BIC) validation constraint [Validator] added BIC (SWIFT-BIC) validation constraint Aug 12, 2015
$canonicalize = str_replace(' ', '', $value);

// the bic must have either 8 or 11 characters
if (8 !== strlen($canonicalize) && 11 !== strlen($canonicalize)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this condition correct? Excuse me! The code is correct. I didn't understand the above comment correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would say yes, if it is not 8 AND not 11 characters long, then buildViolation

@javiereguiluz
Copy link
Member

👍

@mvhirsch
Copy link
Contributor Author

@javiereguiluz updated comment for clarity, because it was not English (I'm sorry).

@mvhirsch
Copy link
Contributor Author

Oh no! I accidentially rebased on master branch, not 2.8.
How can I undo this mistake? Please help me!

@mvhirsch
Copy link
Contributor Author

Okay, I fixed the commit :-)

@OskarStark
Copy link
Contributor

👍

$canonicalize = str_replace(' ', '', $value);

// the bic must be either 8 or 11 characters long
if (8 !== strlen($canonicalize) && 11 !== strlen($canonicalize)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

if (in_array(strlen($canonicalize), array(8, 11))) {

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Triiistan I suspect looping over an array is not faster than performing a &&

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof i think @Triiistan is talking about better readability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to save 1 call from strlen and I tried to find which style Symfony used most between

if (yyy !== xxxx && zzz !== xxxx) {

and

if (!in_array(xxxx, array(yyy, zzz)) { 

and the latter was used a bit more.

With the first style, we can write

$canonicalizeLength = strlen($canonicalize);
if (8 !== $canonicalizeLength && 11 !== $canonicalizeLength) {

to avoid the duplication.

[Updated: I inverted both styles]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, my concern may not be very pragmatic, so go with the version most readable to your eyes 😃

@mvhirsch
Copy link
Contributor Author

@Triiistan I've updated the code to use just one strlen call. It seems legit ;-)

@mvhirsch
Copy link
Contributor Author

Why does the build fail on HHVM?
Can we please re-run the Test-Suite?

EDIT: Thanks to whoever ran the Test-Suite again, it now looks stable at all (even HHVM) :-)

@mvhirsch
Copy link
Contributor Author

mvhirsch commented Sep 8, 2015

Status: Reviewed

@jakzal
Copy link
Contributor

jakzal commented Sep 8, 2015

I'm also not convinced we should have this kind of validators in core, as this is smething that can be easily provided by a 3rd party extension. The IBAN validator gave us a few headaches.

@xabbuh
Copy link
Member

xabbuh commented Sep 8, 2015

I agree that a BIC validator is does not fit best in the core. However, we already have the IBAN validator and for consistency we imho should include this one too.

@OskarStark
Copy link
Contributor

👍 @xabbuh

otherwise 3.0 could be the right moment to remove not wanted stuff from core and move this to a separate bundle, isn't it?

@mvhirsch
Copy link
Contributor Author

mvhirsch commented Sep 8, 2015

@jakzal @xabbuh @OskarStark we could provide a ValidatorExtraBundle or ValidatorFinanceExtraBundle (name proposal) for symfony 3.0. What do you think?
For now we could add this in 2.8.

@OskarStark
Copy link
Contributor

👍 @mvhirsch sounds good to me

@mvhirsch
Copy link
Contributor Author

ping @jakzal @xabbuh

@jakzal
Copy link
Contributor

jakzal commented Sep 14, 2015

@mvhirsch well, yes, but I don't think such a bundle (or component) needs to be provided in the Symfony organisation. It's a perfect candidate for a community extension.

@OskarStark
Copy link
Contributor

anyway, i thin we should merge this as it is.

the Iban is already in so....

@mvhirsch
Copy link
Contributor Author

@jakzal we could add it for 2.8 anyway and extract/remove the parts for 3.0 and provide a community extension for those validators. What do you think?

@xabbuh
Copy link
Member

xabbuh commented Sep 24, 2015

Can you please add translations for the message (at least add it to the validators.en.xlf file)?

@mvhirsch
Copy link
Contributor Author

@xabbuh I added translations for English and German language.

@@ -310,6 +310,10 @@
<source>This value does not match the expected {{ charset }} charset.</source>
<target>Dieser Wert entspricht nicht dem erwarteten Zeichensatz {{ charset }}.</target>
</trans-unit>
<trans-unit id="81">
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Dieser Wert ist keine gültige BIC-Nummer.</target>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to "[...] ist kein gültiger BIC."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fabpot
Copy link
Member

fabpot commented Sep 24, 2015

ping @symfony/deciders

@xabbuh
Copy link
Member

xabbuh commented Sep 24, 2015

👍 (besides my comment on the translation, but this shouldn't hold off merging imo)

@dunglas
Copy link
Member

dunglas commented Sep 24, 2015

Adding a new feature to deprecate it immediately doesn't sound to me like a good idea. IBAN and BIC validation is not so easy and is a very specific use case. I'm in favor of deprecating the IBAN validator in 2.8, remove it from 3.0 and provide a new community library with the IBAN and BIC validators. It would be cool to have a library usable without the DIC component (so no bundle but it can still include an optional extension).

@mvhirsch
Copy link
Contributor Author

@xabbuh I fixed the German translation. Thank you!

@fabpot
Copy link
Member

fabpot commented Sep 25, 2015

As we don't this "community-driven" repository/bundle with such validators, I propose to merge this one for consistency.

@dunglas
Copy link
Member

dunglas commented Sep 25, 2015

agree

@fabpot
Copy link
Member

fabpot commented Sep 25, 2015

Thank you @mvhirsch.

@fabpot fabpot closed this Sep 25, 2015
fabpot added a commit that referenced this pull request Sep 25, 2015
…t (mvhirsch)

This PR was squashed before being merged into the 2.8 branch (closes #15519).

Discussion
----------

[Validator] added BIC (SWIFT-BIC) validation constraint

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | symfony/symfony-docs#5623

I've added the BIC validator, because we do often need validation for IBAN and BIC values. Since the IBAN validation was already included into Symfony, I was asking myself: why not contribute my  BIC validator to the community? So here we go ...

It depends on ISO 9362 as described on [Wikipedia](https://en.wikipedia.org/wiki/ISO_9362#Structure). It validates the structure based on alphabetic/alphanumeric values and the value's length.

Todo-list:
- [x] submit changes to the documentation

Commits
-------

d6471b3 [Validator] added BIC (SWIFT-BIC) validation constraint
@OskarStark
Copy link
Contributor

yay, congrats @mvhirsch and thank you!

xabbuh added a commit to symfony/symfony-docs that referenced this pull request Oct 12, 2015
This PR was squashed before being merged into the 2.8 branch (closes #5623).

Discussion
----------

[Validator] added BIC validator

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes, PR: symfony/symfony#15519
| Applies to    | 2.8
| Fixed tickets | none

Commits
-------

7911fe1 [Validator] added BIC validator
@fabpot fabpot mentioned this pull request Nov 16, 2015
@mvhirsch mvhirsch deleted the bic_validation_constraint branch July 4, 2017 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.