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

IsNumeric Function

Hi. I'm trying to create a simple validation process that only allows a user
to enter a numeric value into a textbox. However, my process does not work
and the user can still enter non-numeric values. My code is below. How can
I fix this? Thanks.

If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text)) Then
Me.lblErrorMsg.Text = "Only numeric values allowed!"
Exit Sub
End If
Nov 18 '05 #1
5 4652
Mike,

A suggestion would be to scrap this code behind and go with client side
validation. What you're doing isn't wrong, but it does mean a post-back has
to a occur before the user will see their error. It's better to have a
CompareValidator that contains your text error string, where the operator =
"DataTypeCheck" and the Type is "Integer"...

This will only allow a postback if the value in the textbox is an integer.

Google on CompareValidator for more, or let me know if you need more help.

Daniel.
"MrMike" <Mr****@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
Hi. I'm trying to create a simple validation process that only allows a
user
to enter a numeric value into a textbox. However, my process does not
work
and the user can still enter non-numeric values. My code is below. How
can
I fix this? Thanks.

If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text)) Then
Me.lblErrorMsg.Text = "Only numeric values allowed!"
Exit Sub
End If

Nov 18 '05 #2
MrMike wrote:
Hi. I'm trying to create a simple validation process that only
allows a user to enter a numeric value into a textbox. However, my
process does not work and the user can still enter non-numeric
values. My code is below. How can I fix this? Thanks.

If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text))
Then Me.lblErrorMsg.Text = "Only numeric values allowed!"
Exit Sub
End If


Use a "CompareValidator", with type set to integer and operator
set to datatypecheck. Don't forget the "ControlToValidate" :-)
Hans Kesting
Nov 18 '05 #3
Mike,
Remember, even though you wrote this code:
Me.lblErrorMsg.Text = "Only numeric values allowed!"

You still don't through an exception, therefore this will still cause the
form to post its values. Like the others explained, use the asp.net
validation controls to stop users from entering bad values

"MrMike" wrote:
Hi. I'm trying to create a simple validation process that only allows a user
to enter a numeric value into a textbox. However, my process does not work
and the user can still enter non-numeric values. My code is below. How can
I fix this? Thanks.

If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text)) Then
Me.lblErrorMsg.Text = "Only numeric values allowed!"
Exit Sub
End If

Nov 18 '05 #4
Thank you all for your posts. I've successfully implemented a
comparevalidator as suggested. I'm still making the transition from Access
VBA to VB.NET :)

Thanks!

"Tampa .NET Koder" wrote:
Mike,
Remember, even though you wrote this code:
Me.lblErrorMsg.Text = "Only numeric values allowed!"

You still don't through an exception, therefore this will still cause the
form to post its values. Like the others explained, use the asp.net
validation controls to stop users from entering bad values

"MrMike" wrote:
Hi. I'm trying to create a simple validation process that only allows a user
to enter a numeric value into a textbox. However, my process does not work
and the user can still enter non-numeric values. My code is below. How can
I fix this? Thanks.

If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text)) Then
Me.lblErrorMsg.Text = "Only numeric values allowed!"
Exit Sub
End If

Nov 18 '05 #5
Thank you all for your posts. I've successfully implemented a
comparevalidator as suggested. I'm still making the transition from
Access
VBA to VB.NET :)


Good to ask questions, even better to listen to the answers. Looking at the
guys around these parts, I realise I know's nothing!
Nov 18 '05 #6

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

Similar topics

8
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the...
4
by: Eugene Anthony | last post by:
I have received the following feedback for the two functions bellow: "The ISNUMERIC test is WORTHLESS for checking for an INT value, because ISNUMERIC will happily accept DOUBLE values, such as...
14
by: Kenny | last post by:
Hello, I would like to know if the function IsNumeric requires a header like #include <iostream> to be functionnal thanks ken
8
by: John Bowman | last post by:
Hello, Does anyone have a good/reliable approach to implementing an IsNumeric() method that accepts a string that may represent a numerical value (eg. such as some text retrieved from an XML...
10
by: michele | last post by:
I have a problem with VB.Net and IsNumeric() function because it always returns FALSE even the string can be a number. There is another strange thing, the same program (it is a test) runs good on...
8
by: Dave | last post by:
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function in my C# code but all I see is: Microsoft.VisualBasic.VBCodeProvider while using Intellisense... From samples shouldn't...
7
by: Nathan Truhan | last post by:
All, I think I may have uncovered a bug in the IsNumeric function, or at least a misunderstanding on functionality. I am writing a Schedule Of Classes Application for our campus and have a...
9
by: Kimelia Schiles | last post by:
Hi, I am new to C#, and I am a VB programmer. I would like to know whether there is any function in C# that can is similar to IsNumeric in VB?
12
by: sck10 | last post by:
Hello, I am trying to determine if a value is NOT numeric in C#. How do you test for "Not IsNumeric"? protected void fvFunding_ItemInserting_Validate(object sender, FormViewInsertEventArgs...
9
by: =?Utf-8?B?VG9ueQ==?= | last post by:
Can anybody tell why IsNumeric("5-") is true?
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
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
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
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
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
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...

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.