生成NSCharacter集以限制UITextField用于输入用户名.我希望用户也能输入一个下划线(因此[A-Za-z0-9_]),但alphanumericCharacterSet不包括它.有没有办法用简写的形式指定这样的范围?我看到了+ (id)characterSetWithRange:(NSRange)aRange
个,但我不太明白这是怎么回事.
我有一个简单的UITextField子类,我将字符集传递给它.该限制可以正常工作,不允许用户输入字母数字以外的任何内容.只需要在这些津贴中加上"ux".
NSCharacterSet *characterSet = [NSCharacterSet alphanumericCharacterSet];
[textField setAllowed:characterSet];
[textField setFrame:frame];