Regex for IBAN allowing for white spaces AND checking for exact length

后端 未结 7 2220
盖世英雄少女心
盖世英雄少女心 2020-12-08 22:56

I need to check an input field for a German IBAN. The user should be allowed to leave in white spaces and input should be validated to have a starting DE

7条回答
  •  轮回少年
    2020-12-09 00:00

    Using Google Apps Script, I pasted Laurent's code from github into a script and added the following code to test.

    // Use the Apps Script IDE's "Run" menu to execute this code.
    // Then look at the View > Logs menu to see execution results.
    
    function myFunction() {
    //https://github.com/arhs/iban.js/blob/master/README.md
    // var IBAN = require('iban');
    var t1 = IBAN.isValid('hello world'); // false
    var t2 = IBAN.isValid('BE68539007547034'); // true
    var t3 = IBAN.isValid('BE68 5390 0754 7034'); // true
    
    Logger.log("Test 1 = %s", t1);
    Logger.log("Test 2 = %s", t2);
    Logger.log("Test 3 = %s", t3);
    }
    

    The only thing needed to run the example code was commenting out the require('iban') line: // var IBAN = require('iban'); Finally, instead of using client handlers to attempt a RegEx validation of IBAN input, I use a a server handler to do the validation.

提交回复
热议问题