Click here to Skip to main content
15,509,705 members
Articles / Web Development / ASP.NET
Posted 14 Mar 2005


12 bookmarked

Function to check numeric data

Rate me:
Please Sign up or sign in to vote.
1.24/5 (34 votes)
14 Mar 2005
This function returns True if the specified data is in digits and returns False if it is not in digits.


This is simple function (written in VB.Net) which tells whether the given string is in digits or not.


To check this I will simply make two functions:
1- Page_Load(Sender As Object, E As EventArgs)
2- Check_For_Numeric_Format(C_S)

We will declare one variable in Page_Load e.g., "Var_String", assign it the value and then call the function "Check_For_Numeric_Format(Var_String)". The code is given below:

Source Code

Sub Page_Load(Sender As Object, E As EventArgs)<BR>   If Not Page.IsPostBack Then<BR>    Dim Var_String<BR>    Var_String = "1234567890"<BR>    If Check_For_Numeric_Format(Var_String) = True Then<BR>     Response.Write("Congratulations! The string is in digits.")<BR>    Else<BR>     Response.Write("Sorry! The string is not in digits.")<BR>    End If<BR>   End If<BR>End Sub<BR><BR>Function Check_For_Numeric_Format(C_S)<BR>   Dim Var_Loop, Var_Len<BR>   If C_S = "" Then<BR>    Return False<BR>   End If<BR>   Var_Len = Len(C_S)<BR>   C_S = LCase(C_S)<BR>   For Var_Loop = 1 To Var_Len<BR>    If Mid(C_S, Var_Loop, 1) < Chr(48) Or Mid(C_S, Var_Loop, 1) > Chr(57) Then<BR>     Return False<BR>    End If<BR>   Next<BR>   Return True<BR>End Function


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Written By
Pakistan Pakistan
I am a computer science graduate. I have been working in ASP.Net since January 2003.

Comments and Discussions

GeneralAwful ! Pin
DynV5-Jul-07 9:49
DynV5-Jul-07 9:49 
This code is awful, cluttered and inefficient ! You should review or people will keep on voting 1 like I did. Mad | :mad:

Je vous salue du Québec !

Question.what? Pin
Anonymous15-Mar-05 3:14
Anonymous15-Mar-05 3:14 
AnswerRe: .what? Pin
Anonymous15-Mar-05 3:15
Anonymous15-Mar-05 3:15 
Questionwhat with 4.32, -33, ? Pin
loui3114-Mar-05 20:44
loui3114-Mar-05 20:44 
AnswerRe: what with 4.32, -33, ? Pin
naveedmazhar15-Mar-05 16:02
naveedmazhar15-Mar-05 16:02 
GeneralRe: what with 4.32, -33, ? Pin
Anonymous23-Aug-05 23:05
Anonymous23-Aug-05 23:05 
QuestionHuh? Pin
Poolbeer14-Mar-05 20:00
Poolbeer14-Mar-05 20:00 
AnswerRe: Huh? Pin
Anonymous4-May-05 20:41
Anonymous4-May-05 20:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.