Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从UIPasteBoard检查NSString格式_Ios_Nsstring_Uipasteboard - Fatal编程技术网

Ios 如何从UIPasteBoard检查NSString格式

Ios 如何从UIPasteBoard检查NSString格式,ios,nsstring,uipasteboard,Ios,Nsstring,Uipasteboard,我允许用户从我的网站复制注册密钥,然后NSStirng保存到剪贴板,当应用程序打开注册对话框时,我立即使用此代码检查剪贴板- NSString *registrationCode = [UIPasteboard generalPasteboard].string; 现在我有了粘贴板上的值,我想检查它的格式。。它应该类似于AAAA-AAAA-AAAA-AAAA所以在essance中没有数字,没有空格(包括前面和结尾),没有小写,没有特殊字符。。。只有大写字符。我怎样才能做到这一点?试着在代码中这

我允许用户从我的网站复制注册密钥,然后NSStirng保存到剪贴板,当应用程序打开注册对话框时,我立即使用此代码检查剪贴板-

NSString *registrationCode = [UIPasteboard generalPasteboard].string;

现在我有了粘贴板上的值,我想检查它的格式。。它应该类似于AAAA-AAAA-AAAA-AAAA所以在essance中没有数字,没有空格(包括前面和结尾),没有小写,没有特殊字符。。。只有大写字符。我怎样才能做到这一点?

试着在代码中这样做:

NSCharacterSet * everythingThatsAllowedSet = [NSCharacterSet characterSetWithCharactersInString: @"ABCDEFGHIJKLMNOPQRSTUVWXYZ-"];
NSCharacterSet * characterSetFromRegistrationCode = [NSCharacterSet characterSetWithCharactersInString: registrationCode];

if([everythingThatsAllowedSet isSupersetOfSet: characterSetFromRegistrationCode ] == YES)
    NSLog( @"this is a valid registration code");
else
{
    // if there are any characters in the registration code that aren't members of
    // the everythingAllowed set, the "isSupersetOfSet" test will fail
    NSLog( @"this has invalid characters");
}

太好了,措辞很好。。现在我要检查谁来检查连字符是否在正确的位置。这样我就可以确定我的粘贴板上有某种类型的注册码。