Unity正则表达式~验证输入类型

 ///<summary> 
    ///检查输入的编号是否为0-9的数字
    ///</summary> 
    ///<param name="strInput"></param>
    ///<returns></returns>
    public bool IsNumber(string strInput){
 
        Regex reg = new Regex("^[0-9]*$");
        if (reg.IsMatch (strInput)) {
            return true;
        } else {
            return false;
        }
    }


  

 ///<summary>
    ///检查输入的号码是否为规定数量的数字 
    ///</summary>
    ///<param name="strInput"></param>
    ///<returns></returns>
    public bool IsPhoneNumber(string strInput){
        //匹配11个数字或8个数字
        Regex reg = new Regex(@"(^\d{11}$)|(^\d{8}$)");
        if (reg.IsMatch (strInput)) {
            return true;
        } else {
            return false;
        }
    }

  

 ///<summary>
    ///检查输入是否为邮箱格式 
    ///</summary>
    ///<param name="strInput"></param>
    ///<returns></returns>
    public bool IsEmail(string strInput){
 
        Regex reg = new Regex ("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$");
        if (reg.IsMatch (strInput)) {
            return true;
        } else {
            return false;
        }
    }

  


---------------------
作者:htwzl
来源:CSDN
原文:https://blog.csdn.net/htwzl/article/details/79615051
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-03-22 14:03  WalkingSnail  阅读(1275)  评论(0)    收藏  举报