The code bellow:

function isInt(input)

isInt = true
for i=1 to len(input)
d = Mid(input,i,1)
if Asc(d) < 48 OR Asc(d) > 57 then
isInt = false
exit for
end if
next

end function


I tried replacing with:

function isInt(input)

Set re = new RegExp
re.Pattern = "[0-9]"
isInt = re.test(input)

end function

But dont seem to work.

How do I solve the problem?.

Your help is kindly appreciated.

Regards

Eugene Anthony


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

Re: validating a non float integer value by Roland

Roland
Wed Jul 13 15:22:16 CDT 2005

Correction:

function isInt(input)
dim re, match
set re = new RegExp
re.Pattern = "\D"
re.Global = True
set match = re.Execute(input)
if match.count > 0 then
isInt = false
else
isInt = true
end if
set match = nothing
set re = nothing
end function

--
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



Re: validating a non float integer value by Roland

Roland
Wed Jul 13 15:21:11 CDT 2005

"Eugene Anthony" wrote in message
news:eKirMG5hFHA.3912@tk2msftngp13.phx.gbl...
: function isInt(input)
: isInt = true
: for i=1 to len(input)
: d = Mid(input,i,1)
: if Asc(d) < 48 OR Asc(d) > 57 then
: isInt = false
: exit for
: end if
: next
: end function
:
: I tried replacing with:
:
: function isInt(input)
: Set re = new RegExp
: re.Pattern = "[0-9]"
: isInt = re.test(input)
: end function

function isInt(input)
dim re, match
set re = new RegExp
re.Pattern = "\D"
re.Global = True
set match = re.Execute(input)
if match.count > 0 then
isInt = false
else
isInt = true
end if
set re = nothing
end function

--
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



Re: validating a non float integer value by Dave

Dave
Wed Jul 13 15:58:01 CDT 2005

Eugene Anthony wrote:
> I tried replacing with:
>
> function isInt(input)
>
> Set re = new RegExp
> re.Pattern = "[0-9]"
> isInt = re.test(input)
>
> end function
>
> But dont seem to work.
>
> How do I solve the problem?.

One way:

Function IsInt(str)
IsInt = CDbl(str) = Int(str)
End Function


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.



Re: validating a non float integer value by Roland

Roland
Wed Jul 13 18:35:05 CDT 2005


"Dave Anderson" <GTSPXOESSGOQ@spammotel.com> wrote in message
news:eLqtP2%23hFHA.3300@TK2MSFTNGP15.phx.gbl...
: Eugene Anthony wrote:
: > I tried replacing with:
: >
: > function isInt(input)
: >
: > Set re = new RegExp
: > re.Pattern = "[0-9]"
: > isInt = re.test(input)
: >
: > end function
: >
: > But dont seem to work.
: >
: > How do I solve the problem?.
:
: One way:
:
: Function IsInt(str)
: IsInt = CDbl(str) = Int(str)
: End Function

Is that valid in vbscript?

--
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



Re: validating a non float integer value by Aaron

Aaron
Thu Jul 14 07:29:45 CDT 2005

> Is that valid in vbscript?

Sure, did you try it?

For readability, I would probably have written the condition line with
parens, e.g.

IsInt = (CDbl(str) = Int(str))

A



Re: validating a non float integer value by Dave

Dave
Thu Jul 14 11:12:01 CDT 2005

Aaron Bertrand [SQL Server MVP] wrote:
> For readability, I would probably have written the condition line with
> parens, e.g.
>
> IsInt = (CDbl(str) = Int(str))

Likewise, for readability I would have written it this way:

function IsInt(s){ return s == parseInt(s,10) }




But readability was off the table, as VBScript was implied in the question.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.



Re: validating a non float integer value by Aaron

Aaron
Thu Jul 14 11:18:20 CDT 2005

> Likewise, for readability I would have written it this way:
>
> function IsInt(s){ return s == parseInt(s,10) }
>
> But readability was off the table, as VBScript was implied in the
> question.

It was just a comment, not criticism, relax.



Re: validating a non float integer value by Dave

Dave
Thu Jul 14 11:26:38 CDT 2005

Aaron Bertrand [SQL Server MVP] wrote:
>> But readability was off the table, as VBScript was implied in the
>> question.
>
> It was just a comment, not criticism, relax.

Mine was a joke, Aaron.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.



Re: validating a non float integer value by Aaron

Aaron
Thu Jul 14 11:41:57 CDT 2005

> Mine was a joke, Aaron.

Ah, I thought you were saying readability was irrelevant. Sorry, I've been
dealing with that a lot recently in the real world, too.



Re: validating a non float integer value by Roland

Roland
Thu Jul 14 19:25:28 CDT 2005

"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:ONSEp%23GiFHA.3540@TK2MSFTNGP14.phx.gbl...
:> Is that valid in vbscript?
:
: Sure, did you try it?
:
: For readability, I would probably have written the condition line with
: parens, e.g.
:
: IsInt = (CDbl(str) = Int(str))

I did and got type mismatch. I was using WSH.

--
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