Does locale in the .range method allow for automatic detection in special language characters?
I can't find any information on this and it's not working in my implementation. And if not, are there any better/other methods of adding support for different language characters? Or is hardcoding UTF values into regex the only way?
The problem being, even if I hardcode Danish characters into the solution, in the future it might need to support other languages, so what's the correct way to go about this?
import Foundation
func isUserNameValid(userName: String, locale: Locale) -> Bool {
return userName.range(
of: #"(?mi)^[a-z](?!(?:.*\.){2})(?!(?:.* ){2})(?!.*\.[a-z])[a-z. ]{1,}[a-z]$"#,
options: .regularExpression,
range: nil,
locale: locale) != nil
}
let inputName = "Lærke"
if isUserNameValid(userName: inputName, locale: Locale(identifier: "da-DK")) {
print("valid")
} else {
print("not valid")
}