Android 判断是否是是全汉字、全字母、全数字、数字和字母等(代码)
程序员文章站
2024-02-23 10:52:28
直接看代码吧!!!
#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 判断是否是是全汉字、全字母、全数字、数字和字母等,希望对大家有所帮助