Velocity Reviews > isNumeric()

# isNumeric()

Eugene Anthony
Guest
Posts: n/a

 07-11-2005
I have received the following feedback for the two functions bellow:

"The ISNUMERIC test is WORTHLESS for checking for an INT value, because
ISNUMERIC will happily accept DOUBLE values, such as 89.11998811777 and
other values that are simply *NOT* INT values."

<%
function isZip(input)

isZip = false

if len(input) = 5 then

isZip = (isNumeric(input))

end if

if len(input) = 10 then

z1 = left(input,5)
z2 = right(input,4)
z3 = mid(input,6,1)

isZip = (isNumeric(z1) and isNumeric(z2) and z3="-")

end if

end function

function isPhone(input)

Dim tempPh

tempPh = replace(input," ","")
tempPh = replace(input,"-","")
tempPh = replace(input,"-","")
tempPh = replace(input,"(","")
tempPh = replace(input,")","")

isPhone = (isNumeric(tempPh))

end function

%>

How do I solve the problem?.

Regards

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***

Bob Barrows [MVP]
Guest
Posts: n/a

 07-11-2005
If all you want to do is test whether it's an integer:

function isInt(pData)
on error resume next
dim test
test=clng(pData)
if err<>0 then
isInt=false
else
if pData <> test then
isInt=false
else
isInt=true
end if
end if
on error goto 0
end function

Eugene Anthony wrote:
> I have received the following feedback for the two functions bellow:
>
> "The ISNUMERIC test is WORTHLESS for checking for an INT value,
> because ISNUMERIC will happily accept DOUBLE values, such as
> 89.11998811777 and other values that are simply *NOT* INT values."
>
>
> <%
> function isZip(input)
>
> isZip = false
>
> if len(input) = 5 then
>
> isZip = (isNumeric(input))
>
> end if
>
> if len(input) = 10 then
>
> z1 = left(input,5)
> z2 = right(input,4)
> z3 = mid(input,6,1)
>
> isZip = (isNumeric(z1) and isNumeric(z2) and z3="-")
>
> end if
>
> end function
>
> function isPhone(input)
>
> Dim tempPh
>
> tempPh = replace(input," ","")
> tempPh = replace(input,"-","")
> tempPh = replace(input,"-","")
> tempPh = replace(input,"(","")
> tempPh = replace(input,")","")
>
> isPhone = (isNumeric(tempPh))
>
> end function
>
> %>
>
>
> How do I solve the problem?.
>
> Your help is kindly appreciated.
>
> Regards
>
> Eugene Anthony
>
> *** Sent via Developersdex http://www.developersdex.com ***

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Eugene Anthony
Guest
Posts: n/a

 07-11-2005
When I did this I am getting an invalid phone and zip code.

function isInt(input)

on error resume next

Dim Tem
Tem = Clng(input)

if err <> 0 then

isInt = false

else

if(Tem <> input) then
isInt = false
else
isInt = true
end if

end if

on error goto 0

end function

function isZip(input)

isZip = false

if len(input) = 5 then

isZip = (isInt(input))

end if

if len(input) = 10 then

z1 = left(input,5)
z2 = right(input,4)
z3 = mid(input,6,1)

isZip = (isInt(z1) and isInt(z2) and z3="-")

end if

end function

function isPhone(input)

Dim tempPh

tempPh = replace(input," ","")
tempPh = replace(input,"-","")
tempPh = replace(input,"-","")
tempPh = replace(input,"(","")
tempPh = replace(input,")","")

isPhone = (isInt(tempPh))

end function

Regards

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***

Roland Hall
Guest
Posts: n/a

 07-11-2005
"Eugene Anthony" wrote in message
news:O0R4u%(E-Mail Removed)...
: When I did this I am getting an invalid phone and zip code.
:
:
: function isInt(input)
:
: on error resume next
:
: Dim Tem
: Tem = Clng(input)
:
: if err <> 0 then
:
: isInt = false
:
: else
:
: if(Tem <> input) then
: isInt = false
: else
: isInt = true
: end if
:
: end if
:
: on error goto 0
:
: end function
:
: function isZip(input)
:
: isZip = false
:
: if len(input) = 5 then
:
: isZip = (isInt(input))
:
: end if
:
: if len(input) = 10 then
:
: z1 = left(input,5)
: z2 = right(input,4)
: z3 = mid(input,6,1)
:
: isZip = (isInt(z1) and isInt(z2) and z3="-")
:
: end if
:
: end function
:
: function isPhone(input)
:
: Dim tempPh
:
: tempPh = replace(input," ","")
: tempPh = replace(input,"-","")
: tempPh = replace(input,"-","")
: tempPh = replace(input,"(","")
: tempPh = replace(input,")","")
:
: isPhone = (isInt(tempPh))
:
: end function

It's probably easier using a regular expression and just have the user enter
just digits.

Ex.

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

function checkPhone(strInput)
dim re, matches, match
set re = new RegExp
re.Pattern = "\d{10}" ' phone 10 digits decimal only
set match = re.Execute(strInput)
if match.count > 0 then
checkPhone = true
else
checkPhone = false
end if
set match = nothing
set re = nothing
end function

Response.Write "9009766969: " & checkPhone("9009766969") & "<br />" & vbCrLf
Response.Write "800XYZ1234: " & checkPhone("800XYZ1234") & "<br />" & vbCrLf
%>

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
MSDN Library - http://msdn.microsoft.com/library/default.asp

Bob Barrows [MVP]
Guest
Posts: n/a

 07-11-2005
Roland Hall wrote:
>
> It's probably easier using a regular expression and just have the
> user enter just digits.
>
> Ex.
>
> <%@ Language=VBScript %>
> <%
> Option Explicit
> Response.Buffer = True
>
> function checkPhone(strInput)
> dim re, matches, match
> set re = new RegExp
> re.Pattern = "\d{10}" ' phone 10 digits decimal only
> set match = re.Execute(strInput)
> if match.count > 0 then
> checkPhone = true
> else
> checkPhone = false
> end if
> set match = nothing
> set re = nothing
> end function
>
> Response.Write "9009766969: " & checkPhone("9009766969") & "<br />" &
> vbCrLf Response.Write "800XYZ1234: " & checkPhone("800XYZ1234") &
> "<br />" & vbCrLf %>
>

And, from http://regexlib.com/REDetails.aspx?regexp_id=924 here's the zip
code pattern:

re.Pattern = "^\d{5}((-|\s)?\d{4})?\$"Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules