I am in the process of developing a registration form. It has the following requirements:
- can contain uppercase and capital letters, numbers, and character set
- must not contain spaces
- length from 5 to 16 characters
I will check the string like this.
extension String {
var isValidUsername: Bool {
let predicate = NSPredicate(format: "SELF MATCHES %@ ", "^(?=.*[A-Za-z0-9!@#$%^&*()._-]).{5,16}$")
return predicate.evaluate(with: self)
}
}
Now there are 2 problems I can enter the spaces, although I should not. I can use characters other than those listed. How do I fix this?