isNumeric()

E

Eugene Anthony

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
 
B

Bob Barrows [MVP]

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
 
E

Eugene Anthony

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
 
R

Roland Hall

in message
: 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/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
B

Bob Barrows [MVP]

Roland said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top