码迷,mamicode.com
首页 > 编程语言 > 详细

Unity的注册表校验(C#)

时间:2014-12-02 20:37:19      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   for   on   div   

using UnityEngine;
using System.Collections;

public class UserRegister : MonoBehaviour {

    void Start () {
       
    }
    public string username = "";
    public string password = "";
    public string rePassword = "";
    public string age = "";
    public string email = "";
    public string gender = "";

    public string showmessage = "";
    public void OnGUI() {

        GUILayout.Label(showmessage);
        GUILayout.Label("用户名:");//用户名(5-10位,只能有字幕,数字,_组成,姓名里只能带有sb两个字)
        username= GUILayout.TextField(username);
        GUILayout.Label("密码:");//(长度为6—10位)
        password = GUILayout.TextField(password);
        GUILayout.Label("重复密码:");
        rePassword = GUILayout.TextField(rePassword);
        GUILayout.Label("年龄:");//1-100
        age = GUILayout.TextField(age);
        GUILayout.Label("Email:");//有一个@,以.com .net  .cn 结尾
        email = GUILayout.TextField(email);
        GUILayout.Label("性别:");//男  或女
        gender = GUILayout.TextField(gender);
        checkInput();
    }
    private string[] domainArray = new string[] { ".com", ".net", ".cn" };
    private void checkInput()
    {
        showmessage = "";
        if (username == "")
        {
            showmessage += "用户名不能为空\n";
        }
        else if (username.Length < 5 || username.Length > 10)
        {
            showmessage += "用户名是5-10位\n";
        }
        else {
            for (int i = 0; i < username.Length; i++)
            {
                char c = username[i];
                if ((c >= a && c < z) || (c > A && c <= Z) || (c >= 0 && c < 9) || (c == _))
                { }
                else
                {
                    showmessage += "用户名只能有字幕,数字,_组成\n";
                }
            }
            if (username.IndexOf("sb") != -1)
            {
                showmessage += "用户名里面不能有敏感字样\n";
            }
        }
        if (password.Length < 6 || password.Length > 10) {
            showmessage += "密码长度为6-10位\n";
        }
        if (rePassword != password) {
            showmessage += "两次输入的密码不一致\n";
        }
        int ageTemp=0;
        if (!int.TryParse(age, out ageTemp))
        {
            showmessage += "年龄必须输入数字\n";
        }else {
            if (ageTemp <= 0 || ageTemp > 100) {
                showmessage += "年龄的范围必须为1-100\n";
            }
        }
        if (email.IndexOf("@") == -1)
        {
            showmessage += "邮箱输入的格式不合法\n";
        }else {
            bool isRight=false;
            for (int i = 0; i < domainArray.Length; i++) {
                if (email.EndsWith(domainArray[i])) {
                    isRight = true; break;
                }
            }
            if (!isRight) {
                showmessage += "邮箱输入的格式不合法\n";
            }
        }
        if (gender == "" || gender == "")
        {
        }
        else {
            showmessage += "性别必须填写男或者女";
        }
    }
}

 

Unity的注册表校验(C#)

标签:style   blog   io   ar   color   sp   for   on   div   

原文地址:http://www.cnblogs.com/heisaijuzhen/p/4138268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!