用户名如何仅包含字母... [英] How the username contain alphabet only ...

查看:112
本文介绍了用户名如何仅包含字母...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很多解决方案..但它仍然保存用户名包含数字..



我尝试了什么: < br $> b $ b

 如果  Regex.Match(TxtUser.Text,  ^ [az] * $, RegexOptions.IgnoreCase)。成功然后 
' 如果TxtUser.Text那么
' Text = TxtUser.Text
cmd.Parameters.Add( @ Username,SqlDbType.VarChar)
cmd。参数( @ Username)。Value = TxtUser.Text

MsgBox ( Pl轻松输入alpha文本。
TxtUser.Focus()
' 否则
' MsgBox(false)
cmd。 Parameters.Add( @ Password1,SqlDbType.VarChar)
cmd.Parameters(< span class =code-string> @ Password1)。Value = TxtPass.Text
con.Open()
ADD.Fill(ds, Tabel
' Server.Transfer(login.aspx,True)
con.Close()
' TextBox1_TextChanged()
会话( loaddata)= ds.Tables( Tabel
如果 ds.Tables( Tabel)。行( 0 )( x )= 0 然后
MsgBox( True
' Server.Transfer(login.aspx,True)
' 响应。重定向(login.aspx)
其他
MsgBox( False
结束 如果
结束 如果

解决方案

,RegexOptions.IgnoreCase)。成功然后
' 如果TxtUser.Text那么
' Text = TxtUser.Text
cmd.Parameters.Add( @ Username,SqlDbType.VarChar)
cmd.Parameters( @ Username)。Value = TxtUser.Text

MsgBox( 请仅输入alpha文本。
TxtUser.Focus()
' 否则
' MsgBox(false)
cmd.Parameters.Add ( @ Password1,SqlDbType.VarChar)
cmd.Parameters( @ Password1)。Value = TxtPass.Text
con.Open()
ADD。填充(ds, Tabel
' Server.Transfer(login.aspx,True)
con.Close()
' TextBox1_TextChanged()
会话( loaddata)= ds.Tables( Tabel
如果 ds.Tables( Tabel)。行( 0 )( x)= 0 然后
MsgBox( True
' Server.Transfer(login.aspx ,True)
' Response.Redirect(login.aspx)
其他
MsgBox( 错误
结束 如果
结束 如果


你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到有一点它会停止你所期望的。

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]



您的代码看起来很混乱,请使用调试器来查看它的确切功能。

您可以随意发表评论,说出您在做什么,这也有助于了解您的意图。


i tried a lot of solutions .. but it still save the username contain numbers ..

What I have tried:

If Not Regex.Match(TxtUser.Text, "^[a-z]*$", RegexOptions.IgnoreCase).Success Then
            'If TxtUser.Text Then
            '    Text = TxtUser.Text
            cmd.Parameters.Add("@Username", SqlDbType.VarChar)
            cmd.Parameters("@Username").Value = TxtUser.Text

            MsgBox("Please enter alpha text only.")
            TxtUser.Focus()
            'Else
            'MsgBox("false")
            cmd.Parameters.Add("@Password1", SqlDbType.VarChar)
            cmd.Parameters("@Password1").Value = TxtPass.Text
            con.Open()
            ADD.Fill(ds, "Tabel")
            'Server.Transfer("login.aspx", True)
            con.Close()
            'TextBox1_TextChanged()
            Session("loaddata") = ds.Tables("Tabel")
            If ds.Tables("Tabel").Rows(0)("x") = 0 Then
                MsgBox("True")
                'Server.Transfer("login.aspx", True)
                'Response.Redirect("login.aspx")
            Else
                MsgBox("False")
            End If
        End If

解决方案

", RegexOptions.IgnoreCase).Success Then 'If TxtUser.Text Then ' Text = TxtUser.Text cmd.Parameters.Add("@Username", SqlDbType.VarChar) cmd.Parameters("@Username").Value = TxtUser.Text MsgBox("Please enter alpha text only.") TxtUser.Focus() 'Else 'MsgBox("false") cmd.Parameters.Add("@Password1", SqlDbType.VarChar) cmd.Parameters("@Password1").Value = TxtPass.Text con.Open() ADD.Fill(ds, "Tabel") 'Server.Transfer("login.aspx", True) con.Close() 'TextBox1_TextChanged() Session("loaddata") = ds.Tables("Tabel") If ds.Tables("Tabel").Rows(0)("x") = 0 Then MsgBox("True") 'Server.Transfer("login.aspx", True) 'Response.Redirect("login.aspx") Else MsgBox("False") End If End If


You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

Your code look confuse, use the debugger to see what it does exactly.
Feel free to put comments that say what you are doing, it also help to understand what is your intention.


这篇关于用户名如何仅包含字母...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆