当前位置:主页 > 移动开发 > Android代码 >

Android 判断是否是是全汉字、全字母、全数字、数字和字母等(代码)

时间:2021-03-04 13:50:12 | 栏目:Android代码 | 点击:

直接看代码吧!!!

#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;
}

您可能感兴趣的文章:

相关文章