mirror of
https://github.com/confirmedcode/Lockdown-iOS.git
synced 2025-12-21 12:14:02 +01:00
41 lines
994 B
Swift
41 lines
994 B
Swift
//
|
|
// String+Extentions.swift
|
|
// Lockdown
|
|
//
|
|
// Created by Aliaksandr Dvoineu on 25.04.23.
|
|
// Copyright © 2023 Confirmed Inc. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension String {
|
|
|
|
enum ValidityType {
|
|
case listName
|
|
case domainName
|
|
case listDescription
|
|
}
|
|
|
|
enum Regex: String {
|
|
case listName = "^[a-zA-Z0-9\\s]{1,20}$"
|
|
case domainName = "^([a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+.*)$"
|
|
case listDescription = "^[a-zA-Z0-9\\s]{1,500}$"
|
|
}
|
|
|
|
func isValid(_ validityType: ValidityType) -> Bool {
|
|
let format = "SELF MATCHES %@"
|
|
var regex = ""
|
|
|
|
switch validityType {
|
|
case .listName:
|
|
regex = Regex.listName.rawValue
|
|
case .domainName:
|
|
regex = Regex.domainName.rawValue
|
|
case .listDescription:
|
|
regex = Regex.listDescription.rawValue
|
|
}
|
|
|
|
return NSPredicate(format: format, regex).evaluate(with: self)
|
|
}
|
|
}
|