Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All
I have a requirement to input in a text box only alphabets and numbers no any special symbols. I m using below code

VB
Private Sub txtLastName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLastName.TextChanged
        If Not Regex.Match(txtLastName.Text, "^[a-z]*$", RegexOptions.IgnoreCase).Success Then
            MessageBox.Show("Please enter alphabets only", "Add Contact", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
            txtLastName.Focus()
        End If
    End Sub



but it allow only alphabets but I need numbers also.What should I do? Please help
Posted
Updated 1-Mar-11 0:50am
v2

Use this regular expression for alpha numeric.
^[a-zA-Z0-9]+$
 
Share this answer
 
Comments
IndrajitDasgupat 1-Mar-11 8:45am    
But it is not allowing paste
IndrajitDasgupat 1-Mar-11 8:46am    
Back space
Wild-Programmer 1-Mar-11 9:06am    
My 5+ to you too :)
Try this regular expression ^[a-zA-Z0-9]+$
 
Share this answer
 
Comments
Manas Bhardwaj 1-Mar-11 6:55am    
you beat me. :) +5
Wild-Programmer 1-Mar-11 8:50am    
:D
IndrajitDasgupat 1-Mar-11 8:45am    
But it is not allowing paste
IndrajitDasgupat 1-Mar-11 8:46am    
and back space

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