[Unity][C#]Regex正则表达式判断字符串

Regex正则表达式判断字符串

字符串中是否含有 汉字、特殊符号、空格、数字、不分大小写英文字母、小写字母、大写字母

...
using System.Text.RegularExpressions;//
...
void Start()
    {
...
        IsValidEmail("你好");
        IsValidEmail("の");
        IsValidEmail("丶");
        IsValidEmail("✎©");
        IsValidEmail("✎©123");
        IsValidEmail("safd✎DF©123");
        IsValidEmail("#");
        IsValidEmail("@");
        IsValidEmail("@@");
        IsValidEmail("@@@");
        IsValidEmail("@@@@");
        IsValidEmail("A@1@23df");
        IsValidEmail("……");
        IsValidEmail("dSD……123");
        IsValidEmail("A@1@23dfsdf%$#6……");
        IsValidEmail("123sdf");
        IsValidEmail("12");
...
}
...

    bool IsValidEmail(string strIn)
        //bool b = Regex.IsMatch(strIn, "[@$#%]");//只含有特定符号
        //bool b = Regex.IsMatch(strIn, "[@$#%].{3,20}$");//必须含有特定符号
        //bool b = Regex.IsMatch(strIn, "[@$#%].{3,4}$");
        //@"[^%&’,;=?$\x22]+"//可以输入含有^%&’,;=?$\”等字符
        //bool b = Regex.IsMatch(strIn, @"[^%&’,;=?$\x22]+");
        //.{3,20}
        bool b = Regex.IsMatch(strIn, "[@$#%]");//只要含有普通符号,就返回真
        Debug.Log("IsValidEmail:"+strIn+"/"+b);
        // Return true if strIn is in valid
        return b;
    }

    public static bool IsNumAndEnCh_2(string input)//中文、英文、数字但不包括下划线等符号
    {
        string pattern = //@"([_]{1}[\s\S]*[_]{1})"
            @"^.{3,20}$";//长度为3-20的所有字符
        Regex regex = new Regex(@"^[\u4E00-\u9FA5A-Za-z0-9]+$");
        Match m = regex.Match(input);
        Debug.Log("input:" + input + "/b1:" + m.Success);
        return regex.IsMatch(input);
    } //https://blog.csdn.net/xpj8888/article/details/98946857
...

字符串中是否 仅仅 含有 汉字、特殊符号、空格、数字、不分大小写英文字母、小写字母、大写字母 ,满足其中的一个条件

...
using System.Text.RegularExpressions;//
...
    public static void test_onlyCN()
    {
        Debug.Log("   只含有 汉字 ================");
        onlyCN("你好");//真,其余为假
        onlyCN("你好123");
        onlyCN("SADF你好cc123");
        onlyCN("你好cc");
        onlyCN("ASF你好FDSAF");
        onlyCN("SADF你好cc");
        onlyCN("你好の");
        onlyCN("你好✎©");
        onlyCN("の");
        onlyCN("丶");//真,其余为假
        onlyCN("✎©");
        onlyCN("✎©123");
        onlyCN("safd✎DF©123");
        onlyCN("#");
        onlyCN("@");
        onlyCN("@@");
        onlyCN("@@@");
        onlyCN("@@@@");
        onlyCN("A@1@23df");
        onlyCN("……");
        onlyCN("dSD……123");
        onlyCN("A@1@23dfsdf%$#6……");
        on
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值