|
-
Oct 20th, 2009, 03:35 PM
#1
Thread Starter
Addicted Member
validation textbox
Hi All.
I validate TextBox for numeric and legth no more then 7 characters. I'm checking for Not IsNumber and Len. But I want to give a user to save record when TextBox is blank. If is it possible how to do it?
Thanks.
-
Oct 20th, 2009, 03:39 PM
#2
Re: validation textbox
Hey,
I am not sure that I fully understand the question?!?
Can you provide more details, plus the code you are already using?
Gary
-
Oct 20th, 2009, 03:48 PM
#3
Re: validation textbox
Code:
Dim BogusDec As Decimal
If (TextBox.Text.Trim.Length = 0I OrElse TextBox.Text.Trim.Length = 7I) AndAlso Decimal.TryParse(TextBox.Text.Trim, BogusDec) Then
'Good to go
End If
-
Oct 20th, 2009, 04:00 PM
#4
Re: validation textbox
Hey,
If that is what the OP is trying to do, then I would be tempted to implement this as a Regular Expression check:
http://www.java2s.com/Tutorial/CShar...oraTextBox.htm
Hope that helps!!
Gary
-
Oct 20th, 2009, 04:04 PM
#5
Re: validation textbox
Not Sure but do you have something like this in vb.net?
vb Code:
Dim BogusDec As Decimal If TextBox.Text.Trim.Length < 8I AndAlso Decimal.TryParse(TextBox.Text.Trim, BogusDec) Then 'Good to go End If
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 20th, 2009, 04:06 PM
#6
Re: validation textbox
Regex is kind of over kill for this simple validation.
Set the textbox.MaxLength = 7 and handle the textbox.validating event. In the event handler, just test if the text is not blank and do a tryparse to make sure it's a valid number.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 20th, 2009, 05:05 PM
#7
Re: validation textbox
 Originally Posted by koolsid
Not Sure but do you have something like this in vb.net?
vb Code:
Dim BogusDec As Decimal
If TextBox.Text.Trim.Length < 8I AndAlso Decimal.TryParse(TextBox.Text.Trim, BogusDec) Then
'Good to go
End If
You don't need to declare that variable if you won't be using it. You can simply pass Nothing for it.
vb.net Code:
If TextBox.Text.Trim.Length < 8 AndAlso Decimal.TryParse(TextBox.Text.Trim, Nothing) Then
'Good to go
End If
[/QUOTE]
-
Oct 20th, 2009, 07:37 PM
#8
Re: validation textbox
 Originally Posted by Pradeep1210
You don't need to declare that variable if you won't be using it. You can simply pass Nothing for it.
vb.net Code:
If TextBox.Text.Trim.Length < 8 AndAlso Decimal.TryParse(TextBox.Text.Trim, Nothing) Then
'Good to go
End If
Didn't know that one, I thought it had to be an actual variable whether you use it or not. It would be nice if the String class had a .IsNumber function like the Char class does.
-
Oct 21st, 2009, 01:23 AM
#9
-
Oct 21st, 2009, 09:35 AM
#10
Re: validation textbox
Its easy to create extension methods.
e.g.
vb.net Code:
Public Module MyExtensionMethods <Extension()> _ Public Function IsNumber(ByVal input As String) As Boolean Return Decimal.TryParse(input, Nothing) End Function End Module
So now you use it just like any other method of the String class:
e.g.
vb.net Code:
Dim myString as String = "12345" MessageBox.Show(myString.IsNumber)
-
Oct 21st, 2009, 09:49 AM
#11
Re: validation textbox
Didn't know that one, I thought it had to be an actual variable whether you use it or not. It would be nice if the String class had a .IsNumber function like the Char class does.
I guess it would be nice, but you can just use the IsNumeric function instead
-
Oct 21st, 2009, 10:05 AM
#12
Re: validation textbox
 Originally Posted by chris128
I guess it would be nice, but you can just use the IsNumeric function instead
The IsNumeric function is good for ordinary use. But it usually won't give the results you would expect. It actually tries anything that can be possible as a number. e.g. hex numbers, commas etc. which you might not expect in normal ways.
e.g.
vb.net Code:
Decimal.TryParse("&H10A", Nothing) '<-- Returns False IsNumeric("&H10A") '<-- Returns True
-
Oct 21st, 2009, 10:13 AM
#13
Re: validation textbox
Oh right, I never knew that, thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|