gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.68k stars 1.59k forks source link

built-in bank-card number valid rule #3360

Closed swift-fs closed 1 month ago

swift-fs commented 8 months ago
func Test_BankCard(t *testing.T) {
    gtest.C(t, func(t *gtest.T) {
        rule := "bank-card"
        val1 := "6230514630000424470"
        val2 := "6230514630000424473"
        // this bocom card  valid result is already true and error is nil
        val3 := "60142870670591508"
        err1 := g.Validator().Data(val1).Rules(rule).Run(ctx)
        err2 := g.Validator().Data(val2).Rules(rule).Run(ctx)
        err3 := g.Validator().Data(val3).Rules(rule).Run(ctx)
        t.AssertNE(err1, nil)
        t.Assert(err2, nil)
        // but no pass
        t.Assert(err3, nil)
    })
}

The bank card number of bocom does not fully follow the luhn algorithm and needs to be optimized and adapted.

swift-fs commented 8 months ago

Currently I have customized the rules to fit older bank card numbers, and this issue can be closed directly.