Validate Numbers With IsNumeric() and Vartype() in VBScript

Validate Numbers With IsNumeric() and Vartype() in VBScript

When accepting input from an HTML form, you can’t assume that the user will provide the right type of data–you have to validate. For instance, if your application expects users to type a number, but they type something that can’t be interpreted as a number, your code could crash. Use the IsNumeric() function to determine whether a value can be safely converted into a number. Another useful function is Vartype() which tells you whether the variable you are using will handle the size of number that you intend to put into it. This code shows both functions in an Active Server Pages script:

 <%@ Language=VBScript %>

Vartype check

<% quantity = request.form("text1")Response.Write "The vartype is: " & vartype(quantity) & "

"If IsNumeric(quantity) then Response.Write "It resembles a number, so let's do quantity=CDbl(quantity)

" quantity= CDbl(quantity) Response.Write "The vartype is now: " & vartype(quantity) & "

"else Response.Write "Whatever you submitted, it can't be converted to a numeric value."end if%>


See also  Digital Signage Solutions for Agile Software Development Teams

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist