注册 用户名字的验证````

  protected   bool  checkzhanhao( string  zhanghao)
    
{
        
bool va = true;
        
if (zhanghao.Length == 0)
        
{
            Response.Write(
"不能为空");    
            va 
= false;
        }
 else if(zhanghao.Length<5||zhanghao.Length>25)
        
{
            Response.Write(
"用户名长度为5-20个字符,请重新输入用户名");
            va 
= false;

        }
else if(!fIsNumber(zhanghao.Substring(0,1),"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
        
{
            Response.Write(
"用户名输入错误,请以字母开头");
            va 
= false;
        }
 else if (!fIsNumber(zhanghao, "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-"))
        
{
            Response.Write(
"用户名应该是数字、字母、下划线、连字符号,不允许出现汉字、空格、点等其他字符,请重新输入用户名!");
             va 
= false;
        }


        
return va;
    }

    
protected   bool  fIsNumber( string  vl,  string  vc)
    
{
        
bool va = false;
        
string temp = "";
        
if (vl.Length == 0)
        
{
            va
= false;
        }

        
else
        
{
            
for (int i = 0; i <vl.Length; i++)
            
{
                temp 
= vl.Substring(i,1);
                
if (vc.IndexOf(temp, 0== -1)
                
{
                    va 
= false;
                }

                
else
                
{
                    va 
= true;
                }

            }

        }

        
return va;
    }
 

你可能感兴趣的:(string)