using UnityEngine;
using System.Collections;
public class UserRegister : MonoBehaviour
{
// Use this for initialization
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("用户名:");
username = GUILayout.TextField(username);
GUILayout.Label("密码:");
password = GUILayout.TextField(password);
GUILayout.Label("重复密码:");
rePassword = GUILayout.TextField(rePassword);
GUILayout.Label("年龄:");
age = GUILayout.TextField(age);
GUILayout.Label("Email:");
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";
}
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 == '_'))
{
// is a right string
}
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 += "性别必须填写男或者女";
}
}
}
使用C#简单完成用户注册功能
猜你喜欢
转载自blog.csdn.net/a834595603/article/details/90083246
今日推荐
周排行