I saw a similar post to this but none of the answers there helped me. I am looking to check if a string does not contain any special characters using swift regular expressions. I want to allow other iPhone keyboard letters though like Chinese, Hindi, Arabic, Korean, etc.. I only do not want to allow special characters like +, &, #, $, % though.
I have tried using:
func usernameTest(testStr:String) -> Bool {
return testStr.range(of: "^[ !\"#$%&'()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~]+", options: .regularExpression) != nil
}
This did not work though. I thought it would check to see if any special characters were used, but when I tested phrases like "Tom@@@." and "%Will!!" it returned false. I would have expected this to return true since the strings that I passed in contained one or more of the special characters in the range.
Any help would be appreciated as we want our users to be able to create their usernames in any language but we still do not want to allow spaces or special characters.