|
Check for an integer
This example checks for a valid positive or negative
integer . It also checks whether a string contains numbers.
Code :
<%
Function CheckInt(intNumber)
'declare our variables
Dim objRegExp , blnValid
'create an instance of regexp object
Set objRegExp = New RegExp
'this is our pattern to check for integers
objRegExp.Pattern = "^[-+]?\d*$"
'chech what was entered
blnValid = objRegExp.Test(intNumber)
'if true then print this message
If blnValid Then
Response.Write "This contains integers<br>"
'if false display this message
Else
Response.Write "does not contain any integers<br>"
End If
End Function
%>
<% CheckInt(12) %>
<% CheckInt(-1545) %>
<% CheckInt("asadsda") %>
<% CheckInt("12") %>
|