Merge pull request #1163 from sidona/iban
Iban: allow lowercased countries in validator
This commit is contained in:
commit
64475a5b3a
3 changed files with 32 additions and 11 deletions
5
.changeset/curvy-suns-cross.md
Normal file
5
.changeset/curvy-suns-cross.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@lion/input-iban': patch
|
||||
---
|
||||
|
||||
allow to specify countries in lowercase
|
||||
|
|
@ -124,12 +124,12 @@ export class IsCountryIBAN extends IsIBAN {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @param {string} modelValue
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
execute(value) {
|
||||
const notIBAN = super.execute(value);
|
||||
if (value.slice(0, 2) !== this.param) {
|
||||
execute(modelValue) {
|
||||
const notIBAN = super.execute(modelValue);
|
||||
if (modelValue.slice(0, 2) !== this.param.toUpperCase()) {
|
||||
return true;
|
||||
}
|
||||
if (notIBAN) {
|
||||
|
|
@ -163,19 +163,20 @@ export class IsNotCountryIBAN extends IsIBAN {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @param {string} modelValue
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
execute(value) {
|
||||
execute(modelValue) {
|
||||
let isInvalid = false;
|
||||
const notIBAN = super.execute(value);
|
||||
|
||||
const notIBAN = super.execute(modelValue);
|
||||
if (typeof this.param === 'string') {
|
||||
if (value.slice(0, 2) === this.param) {
|
||||
if (String(modelValue.slice(0, 2)) === this.param.toUpperCase()) {
|
||||
isInvalid = true;
|
||||
}
|
||||
} else if (Array.isArray(this.param)) {
|
||||
isInvalid = this.param.some(country => value.slice(0, 2) === country);
|
||||
isInvalid = this.param.some(
|
||||
country => String(modelValue.slice(0, 2)) === country.toUpperCase(),
|
||||
);
|
||||
}
|
||||
|
||||
if (notIBAN) {
|
||||
|
|
@ -201,7 +202,6 @@ export class IsNotCountryIBAN extends IsIBAN {
|
|||
userSuppliedCountryCode:
|
||||
typeof data?.modelValue === 'string' ? data?.modelValue.slice(0, 2) : '',
|
||||
};
|
||||
|
||||
// If modelValue is Unparseable, the IsIBAN message is the more appropriate feedback
|
||||
return data?.modelValue instanceof Unparseable
|
||||
? localize.msg('lion-validate+iban:error.IsIBAN', _data)
|
||||
|
|
|
|||
|
|
@ -43,4 +43,20 @@ describe('IBAN validation', () => {
|
|||
expect(deValidator.execute('DE89370400440532013000')).to.be.true;
|
||||
expect(deValidator.execute('SK3112000000198742637541')).to.be.true;
|
||||
});
|
||||
|
||||
it('allows providing lower cased country isos', () => {
|
||||
const nlValidator = new IsCountryIBAN('nl');
|
||||
expect(nlValidator.execute('NL17INGB0002822608')).to.be.false;
|
||||
expect(nlValidator.execute('DE89370400440532013000')).to.be.true;
|
||||
|
||||
const deValidator = new IsNotCountryIBAN('de');
|
||||
expect(deValidator.execute('DE89370400440532013000')).to.be.true;
|
||||
expect(deValidator.execute('NL17INGB0002822608')).to.be.false;
|
||||
|
||||
const deskValidator = new IsNotCountryIBAN(['de', 'sk']);
|
||||
expect(deskValidator.execute('NL17INGB0002822608')).to.be.false;
|
||||
expect(deskValidator.execute('FR1420041010050500013M02606')).to.be.false;
|
||||
expect(deskValidator.execute('DE89370400440532013000')).to.be.true;
|
||||
expect(deskValidator.execute('SK3112000000198742637541')).to.be.true;
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue