欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2024-02-25 22:43:51
直接看代码吧!!! #pragma mark 判断只能为中文的 - (bool) zsstringinputonlyischinese:(nsstring*)s...

直接看代码吧!!!

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

以上所述是小编给大家介绍的android 判断是否是是全汉字、全字母、全数字、数字和字母等,希望对大家有所帮助