473,387 Members | 1,790 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,387 software developers and data experts.

Checking for Alpha

How do I check to see if my textbox has a alpha character in it?

I don't want alpha characters, numeric only.

Thanks

Dooglo

Nov 21 '05 #1
8 1653
Dooglo,

What is alpha in this case, latin alphabeth 26 characters like in the
english/dutch and maybe somemore languages or more characters?

Cor
Nov 21 '05 #2
Here is one way using a reqex expression:

Private Sub txtMyTextbox_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles txtMyTextbox.Validating
Validate_txtMyTextbox()
End Sub

Private Sub Validate_txtMyTextbox()
If txtUsedYTD.Text = String.Empty Then
ErrorProvider1.SetError(txtMyTextbox, "Required")
_error = True
ElseIf Not IsNumeric(txtMyTextbox.Text) Then
ErrorProvider1.SetError(txtMyTextbox, "Not valid")
_error = True
Else
' is it really a number?

Dim rNumber As New
System.Text.RegularExpressions.Regex("(^\d*\.?\d*[0-9]+\d*$)|(^[0-9]+\d*\.\d
*$)")
If rNumber.IsMatch(txtMyTextbox.Text) Then
ErrorProvider1.SetError(txtMyTextbox, "")
Else
ErrorProvider1.SetError(txtMyTextbox, "Not valid")
_error = True
End If
End If
End Sub

HTH,
Greg

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
How do I check to see if my textbox has a alpha character in it?

I don't want alpha characters, numeric only.

Thanks

Dooglo

Nov 21 '05 #3
Hi Doogle,

You can check it while the user types it:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged

If Char.IsLetter(CChar(TextBox1.Text)) = True Then

End If

End Sub

-or chec
http://msdn.microsoft.com/library/de...ettertopic.asp
/Henrik

"Dooglo" wrote:
How do I check to see if my textbox has a alpha character in it?

I don't want alpha characters, numeric only.

Thanks

Dooglo

Nov 21 '05 #4
VJ
If you meant, I need only 0-9 and no other characters... you can use Regular
Expressions..

Imports System.Text.RegularExpressions

Private Function ValidateString(ByVal strText as string) as boolean

Dim retVal as boolean

retVal = RegEx.IsMatch(strText,"[0-9]")

return retVal

End Function

For more regEx expressions see... www.regexlib.com

VJ

"Dooglo" <Do****@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
How do I check to see if my textbox has a alpha character in it?

I don't want alpha characters, numeric only.

Thanks

Dooglo

Nov 21 '05 #5
* =?Utf-8?B?RG9vZ2xv?= <Do****@discussions.microsoft.com> scripsit:
How do I check to see if my textbox has a alpha character in it?

I don't want alpha characters, numeric only.


I would not prevent the user from entering these characters, instead I
would validate input in the textbox's 'Validating' event and make the
user aware of malformed input using an error provider. For example:

\\\
Private Sub TextBox1_Validating( _
ByVal sender As Object, _
ByVal e As CancelEventArgs _
) Handles TextBox1.Validating
Dim SourceControl As TextBox = DirectCast(sender, TextBox)
Try
Dim i As Integer = Integer.Parse(SourceControl.Text)
If Me.ErrorProvider1.GetError(SourceControl).Length > 0 Then
Me.ErrorProvider1.SetError(SourceControl, "")
End If
Catch ex As Exception
Me.ErrorProvider1.SetError( _
SourceControl, "Value must be an integer." & ex.Message & ")" _
)
End Try
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
Misreaded,

So because everybody who visitst this newsgroup have to give a solution
\\\only figures limited to 10 as plus as well as minus is possible as well
as exponents

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.MaxLength = 10
End Sub
Private Sub textbox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox1.KeyUp
If e.KeyValue <> 8 Then
If Not IsNumeric(TextBox1.Text) Then
If TextBox1.Text.Length > 0 Then
MessageBox.Show("Only numeric is allowed")

TextBox1.SelectionStart = TextBox1.Text.Length - 1
TextBox1.SelectionLength = 1
End If

End If
End If
End Sub
Private Sub TextBox1_Validating(ByVal sender _
As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
If TextBox1.Text.Length > 0 Then
If Not IsNumeric(TextBox1.Text) Then
MessageBox.Show("There was an error pasting")
TextBox1.Focus()
e.Cancel = True
End If
End If
End Sub
I hope this helps a little bit?

Cor
Nov 21 '05 #7
Dooglo,

Forgot this question. I was to much looking at the subject

Cor
Nov 21 '05 #8
Thanks everyone for replying.

All examples are great!

"Dooglo" wrote:
How do I check to see if my textbox has a alpha character in it?

I don't want alpha characters, numeric only.

Thanks

Dooglo

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Abby Lee | last post by:
{ if (str.length != 3) return false; else if (str.charAt(0) != ) return false; else if (!Is_Digit(str.charAt(1))) return false; else if (!Is_Digit(str.charAt(2))) return false; else return...
12
by: Randell D. | last post by:
Folks, I have a form called "ourTestForm". Its a test form - nothing special - it contains five input tags - they are named one, two, three, four and five. The input tags are of type...
9
by: Marek Kurowski | last post by:
Yo! What mean when program is ALPHA or BETA version? I suppose it is not release version of program, but I don't know what it exactly mean. What it mean in your opinion? Marek Kurowski
3
by: instruo | last post by:
I'm using the System.Drawing.Bitmap class for loading a 32-bit bmp file which includes an alpha channel. The problem is, when it gets loaded (just using the Bitmap(string filename) constructor),...
1
by: RicercatoreSbadato | last post by:
I have notice that my images have the value Image.Flags = 2 (HasAlpha). How Can I set the Flags to 1? I would like to eliminate the alpha channel... -- RicercatoreSbadato
6
by: TJO | last post by:
Below is some sample code that fades div tags that is not working in IE 6.0.29 on xp sp2. Can anyone help see why the if(ie5) document.getElementById(divID).filters.alpha.opacity lines are not...
0
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the first alpha release of Python 2.5. This is an *alpha* release of Python 2.5, and is the *first*...
6
by: tommaso.gastaldi | last post by:
In a previous post I have been asking about a way to test Alpha Transparency. Bob and Michael have kindly provided some ideas. Here I would like to share the function I have prepared, for the...
3
by: Gernot Frisch | last post by:
Hi, I have this code that blends 2 pixels, but it's not really fast. Can someone help me speeding it up? #define GETR(a) (unsigned char)(((((a)>>11)&31)*255)/31) #define GETG(a) (unsigned...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.