473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

How to display only alphabets?

18
hi... can anybody help me for displaying only alphabets in textboxes in visual studio 2005[asp.net]

i gave[a-zA-Z] in validation expression for regular expression validation...... but still im not getting ....if i giv only aphabets also it showing error......

And aslo i want the expression for displaying alphabets and space
Mar 14 '07 #1
5 6877
shweta123
692 Expert 512MB
Hi,

Check for the ascii values in the KeyPress of Textbox

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90) Or (Asc(e.KeyChar) >= 97 And Asc(e.KeyChar) <= 122) Or Asc(e.KeyChar) = 32 Then
''''''''''''''Process it if want
Else
''''''''''''''If other than alphabets or space make it blank
e.KeyChar = ""
End If
Mar 14 '07 #2
salo
18
Hi,

Check for the ascii values in the KeyPress of Textbox

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90) Or (Asc(e.KeyChar) >= 97 And Asc(e.KeyChar) <= 122) Or Asc(e.KeyChar) = 32 Then
''''''''''''''Process it if want
Else
''''''''''''''If other than alphabets or space make it blank
e.KeyChar = ""
End If
it is webform so keypressed option is not coming and is their any other expression for validation expression
Mar 14 '07 #3
shweta123
692 Expert 512MB
Hi,
Are you using Vb.net?
try this code

Dim objAlphaPattern As New Regex(("[^a-zA-Z]"))

If (objAlphaPattern.IsMatch(TextBox1.Text)) = True Then
TextBox1.Text = ""
End If
Mar 14 '07 #4
ajl
5
You can use ASP.NET's CustomValidator control to validate the textbox control.

Expand|Select|Wrap|Line Numbers
  1. <asp:TextBox ID="textbox1" runat="server" CausesValidation="true" ></asp:TextBox>
  2.  <asp:CustomValidator ID="cvalidator" runat="server" ControlToValidate="textbox1" ErrorMessage="Not a letter or whitespace" ></asp:CustomValidator>
  3.  
  4. If you are using c#, validate function goes as below
  5. <script runat="server">
  6.     protected void Page_Load(object sender, EventArgs e)
  7.     {
  8.       cvalidator.ServerValidate += new ServerValidateEventHandler(txtLetter);
  9.  
  10.     }
  11.     protected void txtLetter(object sender, ServerValidateEventArgs e)
  12.     {
  13.  
  14.         for (int i = 0; i < e.Value.Length; i++)
  15.         {
  16.             if (char.IsLetter(e.Value, i) || char.IsWhiteSpace(e.Value, i))
  17.                 e.IsValid = true;
  18.             else
  19.             {
  20.                 e.IsValid = false;
  21.                 break;
  22.             }
  23.  
  24.         }
  25.  
  26.     }
  27. </script>
Mar 15 '07 #5
[a-zA-z]in this place wrtie code like ^[a-zA-Z]+$ or ^[a-zA-Z]+ its means access more character if u use [a-zA-Z]this code it access only one character u enter one character its not display error i hope its usefull for u
Nov 15 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: rajeevs | last post by:
Hi I have posted earlier about the same but only one reply thanks but i dont know how to do that. Please help again i will explain what i need to do in ms access by using a query i want to trim...
24
by: Adam | last post by:
Hi, Does anyone know of an online C-to-HTML converter to display code nicely formatted in a browser? Thanks a lot, Adam
3
missshaikh
by: missshaikh | last post by:
i need to make a query Sort by alphabets "D" or Sort by alphabets "E" means Sort by A B C D E F G H I J K L M N O P Q R S T U V W X Y Z All
17
nitindel
by: nitindel | last post by:
Hi All, I have a text box and want to validate it like this: I want to enter Numerics or alphanumerics in the text box but not Alphabets alone.If Alphabets alone entered then...
5
by: laurie1388 | last post by:
I'm in an Intro to Software Development course at FIT and I have a homework assignment that I have no idea what to do about. Can anyone help? Do I need to use ASCII? If so, how? Here's the...
1
by: sury | last post by:
I want to split a word into individual alphabets and substitute a word for each of the alphabets in c#. example: If the word entered is LATE, the output wud be L:London A :Apple T:Tom E:Egg
1
by: meeanji | last post by:
Hi friends, i need to write validation for textbox(Usernme ) which should accept only alphabets. I am able throw validation that Please fill the UserName Details.Now it should throw that it accepts...
7
by: prigupta2 | last post by:
i want to type Alphabets and numbers in text box in such a way first alphabets then number ex C102 M458 only CM0123456789 please provide code in vb6.0
4
by: rajeevs | last post by:
Hi Previously I asked this question and I got the answer from the moderator. I am getting all the alphabets, but now i want to get the alphabets before the first occurance of numeric value. I am...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.