Firstname validation in iOS swift4? - Stack Overflow

PHOTO EMBED

Wed Mar 09 2022 08:36:25 GMT+0000 (Coordinated Universal Time)

Saved by @hasnat #ios #swift #name #validation #validate

func isValid(testStr:String) -> Bool {
    guard testStr.count > 7, testStr.count < 18 else { return false }

    let predicateTest = NSPredicate(format: "SELF MATCHES %@", "^(([^ ]?)(^[a-zA-Z].*[a-zA-Z]$)([^ ]?))$")
    return predicateTest.evaluate(with: testStr)
}
content_copyCOPY

https://stackoverflow.com/questions/55181606/how-to-have-a-firstname-validation-in-ios-swift4