Comments (4)
Just use pre defined characters set with unions like
Notation(character: "N", characterSet: CharacterSet(charactersIn: "-").union(CharacterSet.letters), isOptional: false), Then use [N...]
from input-mask-ios.
Mr. @AlexisQapa, thanks for your help.
@SergeyGamayunov, please let us know if this solution fits your needs.
let listener: MaskedTextFieldDelegate
listener.customNotations = [
Notation(
character: "N",
characterSet: CharacterSet(charactersIn: "-").union(CharacterSet.letters),
isOptional: false
),
]
listener.primaryMaskFormat = "[N…]"
from input-mask-ios.
Hey, I just tested it. In a few words - yes, it does, but I had to create some nice workaround for convenient work. In case if you or anybody else would be interested:
That enum represents different character sets. We will combine them in the future.
enum Characters {
case digits, letters, spaceDash, dotNumber
var set: CharacterSet {
switch self {
case .digits:
return CharacterSet.decimalDigits
case .letters:
return CharacterSet.letters
case .spaceDash:
return CharacterSet(charactersIn: " -")
case .dotNumber:
return CharacterSet(charactersIn: ".№")
}
}
}
This enum represents different validation types, and variable for constructing custom notations for every validation type (which are also represented by enum):
enum ValidationType {
case name, oms
private var notations: [Notation] {
var set: [Characters]
var letter: Character
switch self {
case .name:
set = [.letters, .spaceDash]
letter = "N"
case .oms:
set = [.letters, .digits, .dotNumber, .spaceDash]
letter = "O"
default:
return []
}
guard let allowedCharacters = characterSet(unionWith: set) else { return [] }
return [Notation(character: letter, characterSet: allowedCharacters, isOptional: false)]
}
Please, be aware, that this is a sample code, it also includes format, mask and listener variables which are not specific for current topic
from input-mask-ios.
Well, @SergeyGamayunov, your code looks overengineered to me.
First of all, why won't you just extend CharacterSet
?
Second, your enum
is just an abstraction for the sake of abstraction. Especially at this point:
case .digits:
return CharacterSet.decimalDigits
case .letters:
return CharacterSet.letters
Third, here,
guard let allowedCharacters = characterSet(unionWith: set) else { return [] }
— you are creating a disconnected coupling problem, which is a bad design smell.
Bad design like this eventually leads to bug misunderstanding.
In your particular case, MaskedTextFieldDelegate
would throw a mask compilation error exception, while MaskedTextFieldDelegate
nor its internals doesn't have anything with the actual bug: CharacterSet initialisation failure
.
Fourth, a minor one. Please, replace
var set: [Characters]
var letter: Character
with
let set: [Characters]
let letter: Character
from input-mask-ios.
Related Issues (20)
- can you add tailplaceholder as parameter, like MaskedTexfieldDelegate(primaryFormat: [99] / [99], isTailPlaceholderVisible: true) HOT 3
- Move the list of countries to an external file… maybe?
- fix put when primaryMaskFormat "7 ([999])", if we use put("788", textfield) and if string first char is 7 mask will remove it, output: "7 88" HOT 8
- Update the wikis
- Obtain text field value without input-mask HOT 1
- first number of format is wrong with prefix HOT 2
- Being able to use the `UITextField` delegates HOT 11
- First number of mask(#104) HOT 17
- Automatic Caps Lock Activation Issue in MaskedTextField HOT 7
- [Question] How do I initially fill in the mask having only symbols for blanks? HOT 10
- [Question] Character Limit HOT 2
- IOS Objective-C Programmatically example HOT 1
- [!] Unable to determine Swift version for the following pods HOT 1
- Unable to use with single textField HOT 2
- How to define ${dynamic amount }/month in input mask HOT 1
- How to write uppercased text? HOT 2
- Number Formatting (Thousand Separator) HOT 3
- Poor performance when user types fast HOT 3
- can you make mask template always visible while user input text HOT 2
- My repo
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from input-mask-ios.