Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i tried a lot of solutions .. but it still save the username contain numbers ..

What I have tried:

VB.NET
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
Posted
Updated 23-Mar-16 23:41pm
v2
Comments
Richard MacCutchan 24-Mar-16 5:19am    
Apart from your error, you are storing the password in clear text, which is wrong.
Malak Hudaib 24-Mar-16 5:27am    
hi, yes i know ,but now i want the username contain alphabet only..
Richard MacCutchan 24-Mar-16 5:32am    

If Not Regex.Match(TxtUser.Text, "^[a-z]*$", RegexOptions.IgnoreCase).Success Then
' no match, so reject the text
Else
' valid username so accept it
EndIf

Start with that and fill in the relevant code for the two cases.
Member 12392991 25-Mar-16 1:46am    
on textchange event of the txtuser field you may compare the regualar expression against the character you enter. if it is a character set a flag to true otherwise false.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900