{"id":2037,"url":"https://github.com/krizhanovskii/KKStringValidator","last_synced_at":"2025-08-02T23:31:19.206Z","repository":{"id":56917344,"uuid":"74562752","full_name":"krizhanovskii/KKStringValidator","owner":"krizhanovskii","description":"Swift String Validator. Simple lib for ios to validate string and UITextFields text for some criterias","archived":false,"fork":false,"pushed_at":"2016-11-24T12:38:34.000Z","size":56,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-18T04:19:47.559Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krizhanovskii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-23T09:47:07.000Z","updated_at":"2019-12-21T02:59:25.000Z","dependencies_parsed_at":"2022-08-20T21:20:31.698Z","dependency_job_id":null,"html_url":"https://github.com/krizhanovskii/KKStringValidator","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krizhanovskii%2FKKStringValidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krizhanovskii%2FKKStringValidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krizhanovskii%2FKKStringValidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krizhanovskii%2FKKStringValidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krizhanovskii","download_url":"https://codeload.github.com/krizhanovskii/KKStringValidator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228503088,"owners_count":17930508,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:01.838Z","updated_at":"2024-12-06T17:30:30.765Z","avatar_url":"https://github.com/krizhanovskii.png","language":"Swift","funding_links":[],"categories":["Text","UI"],"sub_categories":["Other free courses","Layout","Other Testing","Keychain"],"readme":"# Swift String validator\n\n### About\nLibrary for easy and fastest `string` validation based on сciterias.\n\n### Instalation\nKKStringValidator is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```\npod 'KKStringValidator'\n```\n\n### Main idea\nFor project to project you must validate some `input fields`, `strings`, etc for thay accept some criterias (like `length`, exist `uppercase char`, exist `number`, etc).\n\n***KKStringValidator*** helps to check `string` for needed `criterias` to be accepted.\n\n### Core features\n- validate `string` by one or `array` of `criterias`\n- aviable force fall(break validate) when `criteria` fail\n- default `criterias` exist \n- easy add custom `criteria`\n\n\n\n### Example\n\n```swift\n// import lib\nimport KKStringValidator\n\n// code\n\n    // Create criterias\n    let lennghtCriteria = LengthCriteria(10)\n    let regexpCriteria = RegexpCriteria(\"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,4}\")\n\n    let criterias : [Criteriable] = [lennghtCriteria, UppercaseLetterExistCriteria(), LowercaseLetterExistCriteria(), NumberExistCriteria(), regexpCriteria]\n\n\n    // validate\n    StringValidator(criterias).isValide(\"q1Q\", forceExit: false, result: { validator in\n        switch validator {\n            case .valid:\n                print(\"All valid\")\n            case .notValid(let criteria):\n                print(criteria.debugErrorString)\n            case .notValides(let criterias):\n                print(\"Criterias that fails:\")\n                _ = criterias.map({ print($0.debugErrorString)\n                })\n            }\n    })\n\n```\n\nOutput:\n```swift\nCriterias that fails:\nDEBUG:LengthCriteria:Lenght less than 10\nDEBUG:RegexpCriteria:no mutch to regexp [A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}\n```\n### UITextFieldExtension\nAlso created `extension` for `UITextField`.\n\n```swift \n/// extension for UITextField for validation\nextension UITextField {\n/// function for validating textField text\n///\n/// - Parameters:\n///   - criterias: array of criterias\n///   - forceExit: flag for force extit. default in false\n///   - result: ValidatorResult object\npublic func validate(_ criterias : [Criteriable], forceExit:Bool = false, result:@escaping (ValidatorResult)-\u003eVoid) {\n    //code\n}\n}\n```\n\nExample of usage:\n\n```swift\nfunc textFieldDidEndEditing(_ textField: UITextField) {\n    textField.validate([LengthCriteria(4)], result: { result in\n        switch result {\n            case .valid:\n                print(\"All valid\")\n            case .notValid(let criteria):\n                print(criteria.debugErrorString)\n            case .notValides(let criterias):\n                print(\"Criterias that fails:\")\n                _ = criterias.map({ print($0.debugErrorString)\n                })\n        }\n    })\n}\n```\n\n### How its works\nFirst, you must take needed `criteria` from the `aviable criterias` or create custom `criteria`. All `criterias` must conform `protocol`:\n```swift\nprotocol Criteriable {\n    /// debug string for helps detect problem\n    var debugErrorString : String {get}\n\n    /// Check if value conform to criteria\n    ///\n    /// - Parameter value: value to be checked\n    /// - Returns: return true if conform\n    func isConform(to value:String) -\u003e Bool\n}\n```\n\nThen you can `validate` string by choosed `criterias` by calling:\n```swift\nStringValidator([\\* array of choosed criterias *\\]).isValide(\"\" \\* string to must be validate *\\, forceExit: false, result: { validator in\n        switch validator {\n            /// all criterias was passed\n            case .valid:\n            print(\"All valid\")\n\n            /// first failed criteria\n            case .notValid(let criteria):\n\n            /// all failed criterias\n            case .notValides(let criterias):\n        }\n})\n```\n\nThats all. Your string was validated and you get result. \n\n\n### List of aviable Criterias\n```swift\nstruct LengthCriteria : Criteriable { \\\\code } \\\\ check string length\n\nstruct UppercaseLetterExistCriteria : Criteriable { \\\\code } \\\\ check string contains one or more char in Uppercase\n\nstruct LowercaseLetterExistCriteria : Criteriable { \\\\code } \\\\ check string contains one or more char in Lowercase\n\nstruct NumberExistCriteria : Criteriable { \\\\code } \\\\ check string exist one or more numer\n\nstruct RegexpCriteria : Criteriable { \\\\code } \\\\ check string must to RegExp\n\nstruct RangeCriteria : Criteriable { \\\\code } \\\\ check string length inside range\n\nstruct FirstCharIsLetterCriteria : Criteriable { \\\\code } \\\\ check first char is letter and optional check if in uppercase\n\n```\n\n\n### How add custom Criteria\nIt's easy.\nJust create `struct` and conform protocol `Criteriable`.\n***Example***:\n```swift\nstruct MyCustomCriteria : Criteriable {\n    var debugErrorString: String = debugMessage(MyCustomCriteria.self, message:\"some debug message\")\n    func isConform(to value: String) -\u003e Bool {\n        /* some logic for check */\n        return false\n    }\n}\n```\nThats all. Simple easy :)\n\n\n\n\n\n\n# Author\nk.krizhanovskii, k.krizhanovskii@gmail.com\n\n## License\nKKStatusBarService is available under the MIT license. \n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrizhanovskii%2FKKStringValidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrizhanovskii%2FKKStringValidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrizhanovskii%2FKKStringValidator/lists"}