Check if string contains special characters in Swift

Your code check if no character in the string is from the given set. What you want is to check if any character is not in the given set: if (searchTerm!.rangeOfCharacterFromSet(characterSet.invertedSet).location != NSNotFound){ println(“Could not handle special characters”) } You can also achieve this using regular expressions: let regex = NSRegularExpression(pattern: “.*[^A-Za-z0-9].*”, options: nil, error: … Read more

How to write regular expressions in Objective C (NSRegularExpression)?

A NSTextCheckingResult has multiple items obtained by indexing into it. [match rangeAtIndex:0]; is the full match. [match rangeAtIndex:1]; (if it exists) is the first capture group match. etc. You can use something like this: NSString *searchedString = @”domain-name.tld.tld2″; NSRange searchedRange = NSMakeRange(0, [searchedString length]); NSString *pattern = @”(?:www\\.)?((?!-)[a-zA-Z0-9-]{2,63}(?<!-))\\.?((?:[a-zA-Z0-9]{2,})?(?:\\.[a-zA-Z0-9]{2,})?)”; NSError *error = nil; NSRegularExpression* regex = … Read more

How to validate an e-mail address in swift?

I would use NSPredicate: func isValidEmail(_ email: String) -> Bool { let emailRegEx = “[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}” let emailPred = NSPredicate(format:”SELF MATCHES %@”, emailRegEx) return emailPred.evaluate(with: email) } for versions of Swift earlier than 3.0: func isValidEmail(email: String) -> Bool { let emailRegEx = “[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}” let emailPred = NSPredicate(format:”SELF MATCHES %@”, emailRegEx) return emailPred.evaluate(with: email) } for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)