zoukankan      html  css  js  c++  java
  • ios输入内容正则表达式的应用

    原文链接:http://www.haogongju.net/art/1595705

    由于最近开发ios的程序,由于需要正则表达式的验证,比较麻烦。

    正则表达式的用法比较多,可以网上搜索一下,但是使用的过程中会根据问题区分。

    目前的需求就是,输入的内容不可以是汉字,也不可以有空格,代码如下,判断汉字主要是根据字符所占用的字节数判断。

            BOOL hasChinese = NO;

            int length = [str length];

            for (int i=0; i

                NSRange range = NSMakeRange(i, 1);

                NSString *subString = [str substringWithRange:range];

                const char *cString = [subString UTF8String];

                if (strlen(cString) == 3)

                {

                    hasChinese = YES;

                }

            }

            if (hasChinese) {

                error = [selferror:LoginCheckErrorEmailInvalidatedescription:@"email Invalidate"];

            }else {

                NSString * regex = @"[\S]{1,}";

                NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

                BOOL isMatch = [pred evaluateWithObject:str];

                if (!isMatch) {

                    error = [selferror:LoginCheckErrorPasswordInvalidatedescription:@"Password Invalidate"];

                }

            }

        }

    ================

     

     
  • 相关阅读:
    webp怎么打开 webp怎么转换成jpg
    波浪运动
    缓动
    动画的封装
    单张滑动tab 组件
    明星单品tab
    多个tab选项卡
    下拉框
    购物车css样式效果
    菜单导航兼容和不兼容捕获方法
  • 原文地址:https://www.cnblogs.com/dexjay/p/4890772.html
Copyright © 2011-2022 走看看