|
Is dollar amount correct
This example checks to see if a dollar amount
entered is correct , the valid format is $1.40 . That is a dollar
sign , two decimal places and no non numeric characters.
Code :
<%
Function ValidDollars(dblDollar)
'our variables
Dim objRegExp , blnValid
'create an instance of the Regular expression object
Set objRegExp = New RegExp
'our pattern to match check for correct format
objRegExp.Pattern = "^\$[0-9]+(\.[0-9][0-9])?$"
'store the result , true or false in blnValid
blnValid = objRegExp.Test(dblDollar)
'if test is true display the first message
If blnValid Then
Response.Write "This is a correctly formatted dollar amount<br>"
'incorrect response here
Else
Response.Write "Incorrectly formatted dollar amount<br>"
End If
End Function
%>
<% ValidDollars("$1.35") 'valid %>
<% ValidDollars("1.453") 'invalid too many decimal
place %>
<% ValidDollars("1.35") 'invalid no $ sign %>
<% ValidDollars("$21") 'valid %>
|