直接看代碼吧!!! ...
直接看代碼吧!!!
#pragma mark 判斷只能為中文的
- (BOOL) zsStringInputOnlyIsChinese:(NSString*)string
{
NSString *regex = @"[\u4e00-\u9fa5]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:string]) {
return YES;
}
return NO;
}
#pragma mark 判斷只能為數字的
- (BOOL) zsStringInputOnlyIsNumber:(NSString*)string
{
NSString *regex =@"[0-9]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:string]) {
return YES;
}
return NO;
}
#pragma mark 判斷只能為字母的
- (BOOL) zsStringInputOnlyIsLetter:(NSString*)string
{
NSString *regex =@"[a-zA-Z]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:string]) {
return YES;
}
return NO;
}
#pragma mark 判斷只能為字母或數字的
- (BOOL) zsStringInputOnlyIsNumber:(NSString*)string
{
NSString *regex =@"[a-zA-Z0-9]*";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:string]) {
return YES;
}
return NO;
}