Проверка шаблона шины для iOS
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- import Foundation
-
- public extension MeetupId {
- static func onlyAllowJoin(_ s: String) -> Bool? {
- s.hasPrefix("123")
- }
-
- static func onlyFormat(_ s: String) -> String? {
- let digits = s.components(separatedBy: NSCharacterSet.decimalDigits.inverted).reduce("") { $0 + $1 }
- var r = ""
- var i = 0
- // Делим каждые три цифры дефисом.
- for v in digits {
- r += String(v)
- i = i + 1
- if i % 3 == 0 {
- r += "-"
- }
- }
- // Исключаем дефис в конце.
- if r.hasSuffix("-") {
- r = String(r.dropLast(1))
- }
- return r
- }
- }
|