[ad_1]
Your regex checks for one alphanumeric character. It prints 4.
I suppose you wish to examine if there may be any non- alphanumeric character within the string. In that case you need to invert the sample.
func validate(string : String) -> Bool {
let sample = "[^A-Za-z0-9]"
guard let vary = str.vary(of: sample, choices: .regularExpression) else {
return true
}
print("substring", String(str[range]))
return false
}
The operate returns true if all characters within the string are alphanumeric characters, in any other case false.
Alternatively you’ll be able to examine
guard let vary = str.rangeOfCharacter(from: .alphanumerics.inverted) else {
[ad_2]
