RedMadRobot / input-mask-ios

User input masking library repo.
MIT License
578 stars 96 forks source link

[Question] Character Limit #115

Closed muradtries closed 3 months ago

muradtries commented 6 months ago

Is there any shorthand syntax for setting character limit for homogeneous mask? I looked through the wiki, but couldn't find related information.

elshadpb commented 4 months ago

@muradtries For example, you have Notation like below:

                Notation(
                    character: "N",
                    characterSet: CharacterSet.letters
                        .union(CharacterSet.decimalDigits)
                        .union(CharacterSet.whitespaces)
                        .union(CharacterSet.symbols)
                        .union(CharacterSet.punctuationCharacters),
                    isOptional: false
                )

You can add count limit like below:

    public enum InputMaskType {
        case text(_ charCount: Int?)
        case amount

        var maskValue: String {
            switch self {
            case .text(let charCount):
                if let charCount, charCount > 0 {
                    return "[\(String(repeating: "N", count: charCount))]"
                } else {
                    return "[N…]"
                }
            case .amount:
                return "[0999999999]{.}[00]"
        }
    }
muradtries commented 3 months ago

Thanks a lot @elshadpb for possible solution. As there is no other alternative currently, I'm going to close this issue.