65.9K
CodeProject is changing. Read more.
Home

Function to check numeric data

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.24/5 (25 votes)

Mar 14, 2005

viewsIcon

50838

This function returns True if the specified data is in digits and returns False if it is not in digits.

Introduction

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

Description

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)
If Not Page.IsPostBack Then
Dim Var_String
Var_String = "1234567890"
If Check_For_Numeric_Format(Var_String) = True Then
Response.Write("Congratulations! The string is in digits.")
Else
Response.Write("Sorry! The string is not in digits.")
End If
End If
End Sub

Function Check_For_Numeric_Format(C_S)
Dim Var_Loop, Var_Len
If C_S = "" Then
Return False
End If
Var_Len = Len(C_S)
C_S = LCase(C_S)
For Var_Loop = 1 To Var_Len
If Mid(C_S, Var_Loop, 1) < Chr(48) Or Mid(C_S, Var_Loop, 1) > Chr(57) Then
Return False
End If
Next
Return True
End Function