C#中,一个注册表中,如何是实现选填项和必填项。。。

作者在 2011-11-20 12:48:52 发布以下内容
其中,用户名,密码,邮箱为必填项,其余为选填项。。。还有,密码的格式只能是数字或字母,这个如何设置,求帮助。。。
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace 网站注册表
{
    class Program
    {
        class zhucebiao
        {
            private string name;
            private string mima;
            private string email;
            private string xingbie;
            private int old;
            private string phonenumber;
            public  static int count = 0;
            public zhucebiao()
            {
                count++;
            }
            public void getxingbie()//提示用户输入性别只能从B和G中选择,B-男,G-女
            {
                Console.WriteLine("请输入您的性别B-男,G-女:");
            //  this.xingbie = Convert.ToChar(Console.Read());
                this.xingbie = Console.ReadLine();
                Regex r = new Regex("[BG]{1}");
                if (r.IsMatch(xingbie))
                {
                    Console.WriteLine("性别输入正确。");
                }
                else
                {
                    Console.WriteLine("性别输入格式不符合要求,输入失败,请重新输入:");
                    getxingbie();
                   
                }
            }
            public void getold() //提示用户输入年龄
            {
                Console.WriteLine("请输入您的年龄:");
                this.old = Convert.ToInt32(Console.ReadLine());
            }
            public void getphonenumber()//提示用户输入电话只能是11位号码
            {
                Console.WriteLine("请输入您的电话(只能输入11位数字):");
                this.phonenumber = Console.ReadLine();
                Regex r = new Regex("^[0-9]{11}$");
                if (r.IsMatch(phonenumber))
                {
                    Console.WriteLine("电话输入正确。");
                }
                else
                {
                    Console.WriteLine("电话格式不正确,输入失败,请重新输入:");
                    getphonenumber();
                }
            }
            public void getname()//提示用户输入名字2-6个汉字
            {
              
                Console.WriteLine("请输入您的名字(2-6个汉字):");
                this.name = Console.ReadLine();
                Regex r = new Regex("^[\u4e00-\u9fa5]{2,6}$");
                if (r.IsMatch(name))
                {
                    Console.WriteLine("用户名正确。");
                }
                else
                {
                    Console.WriteLine("用户名格式不符合要求,输入失败,请重新输入:");
                    getname();
                }
               
            }
            public void getmima() //提示用户输入密码
            {
                Console.WriteLine("请输入您的密码(数字或字母,字母区分大小写):");
                this.mima = Console.ReadLine();
          //      Regex r = new Regex("[a-z]*|[0-9]*|[A-Z]*$");
                Regex r = new Regex("[a-z]*$");
                if (r.IsMatch(mima))
                {
                    Console.WriteLine("密码输入正确,请再次输入密码:");
                    string s = Console.ReadLine();
                    if (s == mima)
                    { Console.WriteLine("两次密码输入相同,密码设置成功。"); }
                    else
                    {
                        Console.WriteLine("两次密码输入不同,密码设置失败,请重新输入:");
                        getmima();
                    }
                }
                else
                {
                    Console.WriteLine("密码格式不符合要求,输入失败,请重新输入:");
                    getmima();
                }
            }
            public void getemail() //提示用户输入邮箱
            {
                Console.WriteLine("请输入您的邮箱:");
                this.email = Console.ReadLine();
            }
            public void getUinformation()
            {
                getxingbie();
                getold();
                getphonenumber();
            }
            public void getNinformation()
            {
                getname();
                getmima();
                getemail();
                Console.WriteLine("您的必填信息已成功注册,您是否要完善其他有关信息,请选择:1-是,0-否");
                if (1 == Convert.ToInt32(Console.ReadLine()))
                {
                    getUinformation();
                    Console.WriteLine("您的信息已完善,谢谢!");
                }
                else
                    Console.WriteLine("您的本次操作已经结束,谢谢!");
            }
        }
        static void Main(string[] args)
        {
            zhucebiao a = new zhucebiao();
            a.getNinformation();
            Console.ReadLine();
        }
    }
}
默认分类 | 阅读 1622 次
文章评论,共0条
游客请输入验证码
文章分类
文章归档
最新评论