KKStringValidator alternatives and similar libraries
Based on the "Text" category.
Alternatively, view KKStringValidator alternatives based on common mentions on social networks and blogs.
-
PhoneNumberKit
A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber. -
ZSSRichTextEditor
A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view -
Twitter Text Obj
Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform. -
FontAwesomeKit
Icon font library for iOS. Currently supports Font-Awesome, Foundation icons, Zocial, and ionicons. -
TwitterTextEditor
A standalone, flexible API that provides a full-featured rich text editor for iOS applications. -
RichEditorView
DISCONTINUED. RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing. -
SwiftyMarkdown
Converts Markdown files and strings into NSAttributedStrings with lots of customisation options. -
Atributika
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement. -
SwiftIconFont
Icons fonts for iOS (Font Awesome 5, Iconic, Ionicon, Octicon, Themify, MapIcon, MaterialIcon, Foundation 3, Elegant Icon, Captain Icon) -
NSStringEmojize
A category on NSString to convert Emoji Cheat Sheet codes to their equivalent Unicode characters -
Mustard
🌭 Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it. -
Heimdall
Heimdall is a wrapper around the Security framework for simple encryption/decryption operations. -
AttributedTextView
Easiest way to create an attributed UITextView (with support for multiple links and from html)
InfluxDB - Power Real-Time Data Analytics at Scale
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of KKStringValidator or a related project?
README
Swift String validator
About
Library for easy and fastest string
validation based on сciterias.
Instalation
KKStringValidator is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'KKStringValidator'
Main idea
For project to project you must validate some input fields
, strings
, etc for thay accept some criterias (like length
, exist uppercase char
, exist number
, etc).
KKStringValidator helps to check string
for needed criterias
to be accepted.
Core features
- validate
string
by one orarray
ofcriterias
- aviable force fall(break validate) when
criteria
fail - default
criterias
exist - easy add custom
criteria
Example
// import lib
import KKStringValidator
// code
// Create criterias
let lennghtCriteria = LengthCriteria(10)
let regexpCriteria = RegexpCriteria("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}")
let criterias : [Criteriable] = [lennghtCriteria, UppercaseLetterExistCriteria(), LowercaseLetterExistCriteria(), NumberExistCriteria(), regexpCriteria]
// validate
StringValidator(criterias).isValide("q1Q", forceExit: false, result: { validator in
switch validator {
case .valid:
print("All valid")
case .notValid(let criteria):
print(criteria.debugErrorString)
case .notValides(let criterias):
print("Criterias that fails:")
_ = criterias.map({ print($0.debugErrorString)
})
}
})
Output:
Criterias that fails:
DEBUG:LengthCriteria:Lenght less than 10
DEBUG:RegexpCriteria:no mutch to regexp [A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}
UITextFieldExtension
Also created extension
for UITextField
.
/// extension for UITextField for validation
extension UITextField {
/// function for validating textField text
///
/// - Parameters:
/// - criterias: array of criterias
/// - forceExit: flag for force extit. default in false
/// - result: ValidatorResult object
public func validate(_ criterias : [Criteriable], forceExit:Bool = false, result:@escaping (ValidatorResult)->Void) {
//code
}
}
Example of usage:
func textFieldDidEndEditing(_ textField: UITextField) {
textField.validate([LengthCriteria(4)], result: { result in
switch result {
case .valid:
print("All valid")
case .notValid(let criteria):
print(criteria.debugErrorString)
case .notValides(let criterias):
print("Criterias that fails:")
_ = criterias.map({ print($0.debugErrorString)
})
}
})
}
How its works
First, you must take needed criteria
from the aviable criterias
or create custom criteria
. All criterias
must conform protocol
:
protocol Criteriable {
/// debug string for helps detect problem
var debugErrorString : String {get}
/// Check if value conform to criteria
///
/// - Parameter value: value to be checked
/// - Returns: return true if conform
func isConform(to value:String) -> Bool
}
Then you can validate
string by choosed criterias
by calling:
StringValidator([\* array of choosed criterias *\]).isValide("" \* string to must be validate *\, forceExit: false, result: { validator in
switch validator {
/// all criterias was passed
case .valid:
print("All valid")
/// first failed criteria
case .notValid(let criteria):
/// all failed criterias
case .notValides(let criterias):
}
})
Thats all. Your string was validated and you get result.
List of aviable Criterias
struct LengthCriteria : Criteriable { \\code } \\ check string length
struct UppercaseLetterExistCriteria : Criteriable { \\code } \\ check string contains one or more char in Uppercase
struct LowercaseLetterExistCriteria : Criteriable { \\code } \\ check string contains one or more char in Lowercase
struct NumberExistCriteria : Criteriable { \\code } \\ check string exist one or more numer
struct RegexpCriteria : Criteriable { \\code } \\ check string must to RegExp
struct RangeCriteria : Criteriable { \\code } \\ check string length inside range
struct FirstCharIsLetterCriteria : Criteriable { \\code } \\ check first char is letter and optional check if in uppercase
How add custom Criteria
It's easy.
Just create struct
and conform protocol Criteriable
.
Example:
struct MyCustomCriteria : Criteriable {
var debugErrorString: String = debugMessage(MyCustomCriteria.self, message:"some debug message")
func isConform(to value: String) -> Bool {
/* some logic for check */
return false
}
}
Thats all. Simple easy :)
Author
k.krizhanovskii, [email protected]
License
KKStatusBarService is available under the MIT license.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*Note that all licence references and agreements mentioned in the KKStringValidator README section above
are relevant to that project's source code only.