Last active
July 14, 2017 19:21
-
-
Save tsraveling/5ece8fb896f101d71176ecf94cdf63ca to your computer and use it in GitHub Desktop.
Regex pattern check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @.*[a-zA-z0-9_]$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let pattern = "^([A-Za-z\\d_]+$)" // this checks for usernames matching alphanumeric + _ | |
| let regex = try! NSRegularExpression(pattern: pattern, options: []) | |
| let range = NSMakeRange(0, updatedText.characters.count) | |
| let num_matches = regex.numberOfMatches(in: updatedText, options: [], range: range) | |
| guard updatedText.characters.count == 0 || num_matches == 1 else { | |
| return false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment