IOS正则表达式判断输入类型(整理)
程序员文章站
2022-03-10 21:55:32
在开发过程中,有时需要对用户输入的类型做判断,最常见是在注册页面即用户名和密码,代码整理如下:
只能为中文
-(bool)onlyinputchinesecha...
在开发过程中,有时需要对用户输入的类型做判断,最常见是在注册页面即用户名和密码,代码整理如下:
只能为中文
-(bool)onlyinputchinesecharacters:(nsstring*)string{ nsstring *zhstring = @"[\u4e00-\u9fa5]+"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",zhstring]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
只能为数字
- (bool)onlyinputthenumber:(nsstring*)string{ nsstring *numstring =@"[0-9]*"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",numstring]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
只能为小写
- (bool)onlyinputlowercaseletter:(nsstring*)string{ nsstring *regex =@"[a-z]*"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",regex]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
*只能为大写
- (bool)onlyinputacapital:(nsstring*)string{ nsstring *regex =@"[a-z]*"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",regex]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
允许大小写
- (bool)inputcapitalandlowercaseletter:(nsstring*)string{ nsstring *regex =@"[a-za-z]*"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",regex]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
允许含大小写或数字(不限字数)
- (bool)inputlettersornumbers:(nsstring*)string{ nsstring *regex =@"[a-za-z0-9]*"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",regex]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
允许含大小写或数字(限字数)
-(bool)inputnumberorletters:(nsstring*)name { nsstring *usernameregex = @"^[a-za-z0-9]{6,20}+$"; nspredicate *usernamepredicate = [nspredicate predicatewithformat:@"self matches %@",usernameregex]; bool inputstring = [usernamepredicate evaluatewithobject:name]; return inputstring; }
允许汉字或数字(不限字数)
- (bool)inputchineseornumbers:(nsstring*)string{ nsstring *regex =@"[\u4e00-\u9fa5]+[0-9]*"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",regex]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
允许汉字或数字(限字数)
- (bool)inputchineseornumberslimit:(nsstring*)string{ nsstring *regex =@"[\u4e00-\u9fa5][0-9]{6,20}+$"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",regex]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
允许汉字,大小写或数字(不限字数)
- (bool)inputchineseorlettersandnumbersnum:(nsstring*)string{ nsstring *regex =@"[\u4e00-\u9fa5]+[a-za-z0-9]*"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",regex]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
允许汉字,大小写或数字(限字数)
- (bool)inputchineseorlettersnumberslimit:(nsstring*)string{ nsstring *regex =@"[\u4e00-\u9fa5]+[a-za-z0-9]{6,20}+$"; nspredicate *predicate = [nspredicate predicatewithformat:@"self matches %@",regex]; bool inputstring = [predicate evaluatewithobject:string]; return inputstring; }
以上所述是小编给大家介绍的ios正则表达式判断输入类型(整理),希望对大家有所帮助
上一篇: js获取?后面的参数
推荐阅读
-
使用Reachability类判断iOS设备的当前网络连接类型
-
iOS中使用正则表达式NSRegularExpression 来验证textfiled输入的内容
-
C#正则表达式判断输入日期格式是否正确
-
iOS开发:Swift里正则表达式的正确用法(限制TextField的文本输入,登录时判断正确的手机号)
-
使用Reachability类判断iOS设备的当前网络连接类型
-
如何判断手机端获取哪种类型的手机系统?(安卓或ios)
-
常用的JQuery数字类型验证正则表达式整理
-
Java 判断输入的IP地址是否合法(非正则表达式)
-
iOS正则表达式判断纯数字以及匹配11位手机号码
-
Javascript判断客户端是Android还是IOS,判断浏览器类型