[Form] [Validator] Added IBAN validator #6677

Merged
merged 1 commit into from Apr 20, 2013

Conversation

Projects
None yet
Contributor

sprain commented Jan 10, 2013

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
License of the code: MIT

Validation for International Bank Account Numbers
http://en.wikipedia.org/wiki/International_Bank_Account_Number

I don't know if the community likes new validators. I have been using this in many projects and would love to see it integrated directly with Symfony.

Contributor

stloyd commented Jan 10, 2013

First of... please fix Coding Standards to match Symfony2. =)

+ */
+ public function validate($value, Constraint $constraint)
+ {
+
@stloyd

stloyd Jan 10, 2013

Contributor

Missing empty string validation skip:

if (null === $value || '' === $value) {
    return;
}
src/Symfony/Component/Validator/Constraints/IbanValidator.php
+ $teststring = preg_replace_callback('/[A-Za-z]/',$letterToInt, $teststring);
+
+ $rest=0;
+ for ($pos=0; $pos<strlen($teststring); $pos+=7) {
@stloyd

stloyd Jan 10, 2013

Contributor

Please move strlen() out of loop.

Contributor

sprain commented Jan 10, 2013

Thanks for your feedback. I updated the code and hope things are ok now.

src/Symfony/Component/Validator/Constraints/IbanValidator.php
+ }
+
+ $teststring = preg_replace('/\s+/', '', $value);
+ $teststring = substr($teststring,4)
@stof

stof Jan 10, 2013

Member

missing space after the comma

src/Symfony/Component/Validator/Constraints/IbanValidator.php
+ $teststring = preg_replace('/\s+/', '', $value);
+ $teststring = substr($teststring,4)
+ . strval(ord($teststring{0})-55)
+ . strval(ord($teststring{1})-55)
@stof

stof Jan 10, 2013

Member

missing spaces around the operator.

and you cannot access $teststring{1} without checking first that it exists

src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php
+ {
+ $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
+ $this->validator = new IbanValidator();
+ $this->validator->initialize($this->context);
@stof

stof Jan 10, 2013

Member

Please use 4 spaces per indentation level

src/Symfony/Component/Validator/Constraints/Iban.php
+ */
+class Iban extends Constraint
+{
+ public $message = 'This is not a valid International Bank Account Number (IBAN).';
@stof

stof Jan 10, 2013

Member

you need to add this message in validators.en.xlf (and in any other language for which you are able to provide the translation)

Contributor

alexandresalome commented Jan 10, 2013

In french (fr_FR) it's "Le numéro IBAN saisi n'est pas valide (International Bank Account Number)."

Contributor

sprain commented Jan 11, 2013

Updated!
Any ideas why PHPStorm keeps messing with my indentation levels after saving a file?

Contributor

stloyd commented Jan 11, 2013

@sprain You can use in PHPStrom: Edit -> Convert Indents -> To Spaces if it won't help you should change settings: File -> Settings -> Code Style -> General (or PHP) and turn of "Use tab character".

Contributor

webmozart commented Feb 21, 2013

Thank you for this implementation! Could you please add tests for the null and empty string cases? (see the other validator tests)

Also, as was said, please fix the indentation.

Contributor

sprain commented Feb 21, 2013

Thanks for the feedback.
Will do when I am back from vacation, in 10 days or so.

@@ -222,6 +222,10 @@
<source>Unsupported card type or invalid card number.</source>
<target>Nicht unterstützer Kartentyp oder ungültige Kartennummer.</target>
</trans-unit>
+ <trans-unit id="59">
+ <source>This is not a valid International Bank Account Number (IBAN).</source>
+ <target>Dieser Wert ist keine gültige IBAN-Kontonummer.</target>
@Baachi

Baachi Feb 22, 2013

Contributor

Wrong indention. Maybe tabs vs spaces

+ protected function setUp()
+ {
+ $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
+ $this->validator = new IbanValidator();
@Baachi

Baachi Feb 22, 2013

Contributor

Wrong indentation.

Owner

fabpot commented Mar 26, 2013

@sprain What's the status of this PR? Can you take the comments into account?

Contributor

sprain commented Mar 26, 2013

Thanks for the reminder! I just pushed an update. Hope things are fine now.

Exactly what I needed.
Now waiting for merge!

src/Symfony/Component/Validator/Constraints/Iban.php
+/**
+ * @Annotation
+ *
+ * @api
@Tobion

Tobion Apr 12, 2013

Member

please remove @api as it will be decided later

Hi, any updates on this one? Adding these would be quite usefull for a couple of projects... Thanks!

@kimausloos You can use the SprainValidator has a seperate extension until then

https://github.com/sprain/SprainValidatorBundle

@AAtticus Thanks, that's the plan but it would be nice if I wouldn't have to add an extra bundle as they impact speed and memory usage :)

[Validator] Added IBAN validator
Validation for International Bank Account Numbers

fabpot added a commit that referenced this pull request Apr 20, 2013

merged branch sprain/validator-iban (PR #6677)
This PR was merged into the master branch.

Discussion
----------

[Form] [Validator] Added IBAN validator

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
License of the code: MIT

Validation for International Bank Account Numbers
http://en.wikipedia.org/wiki/International_Bank_Account_Number

I don't know if the community likes new validators. I have been using this in many projects and would love to see it integrated directly with Symfony.

Commits
-------

c8906f4 [Validator] Added IBAN validator

@fabpot fabpot merged commit c8906f4 into symfony:master Apr 20, 2013

1 check failed

default Scrutinizer: No Comments — Travis: Errored
Details

@sprain sprain referenced this pull request in symfony/symfony-docs Apr 20, 2013

Merged

Added Iban constraint documentation #2521

@sprain sprain deleted the sprain:validator-iban branch Apr 20, 2013

Contributor

rvanlaak commented Oct 6, 2013

According to the news items on the following page it seems that there have been a lot of changes due to country specific differences.

https://code.google.com/p/php-iban/

Should Symfony's Iban Validator be adjusted to that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment