473,395 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

validating a non float integer value

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 ***
Jul 22 '05 #1
11 3711
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
Jul 22 '05 #2
"Eugene Anthony" wrote in message
news:eK**************@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
Jul 22 '05 #3
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.
Jul 22 '05 #4
I have discovered that it can also be done as bellow:

function isInt(input)

Set re = new RegExp
re.Pattern = "^\d+$"
re.Global = true
isInt = re.test(input)

end function

The one which you have shown me, I shall study it as well.

Regards

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #5

"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:eL****************@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
Jul 22 '05 #6
> 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
Jul 22 '05 #7
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.
Jul 22 '05 #8
> 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.
Jul 22 '05 #9
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.
Jul 22 '05 #10
> 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.
Jul 22 '05 #11
"Aaron Bertrand [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:ON****************@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
Jul 22 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sashi | last post by:
Two questions: (1) I can pull the text of an XML element as a string just fine using code as such: strSomeString = myXmlDoc.SelectSingleNode("/Element1/Element2/Element3",...
22
by: hantie | last post by:
In my program, for reducing the complexity, the integer was stored as char, so 2 is stored as '2', which is decimal: 50 Is is possible for me to obtain the integer value of '2' in the program,...
1
by: Vaj | last post by:
Hi, when i'm Validating the Age TextBox like this if(txtAge.Text>125) reqage.ErrorMessage="age should be less than 125"; . I'm getting an errormessage "cannot use > to compare a string with...
5
by: Joergen Bech | last post by:
Basically, I want to convert hex values in the range "00000000" to "FFFFFFFF" to a signed, 32-bit Integer value. In VB6, I could just write lngValue = Val(hexstring$). In VB.Net, I seem to be...
8
by: Alex Fraser | last post by:
Can negating a non-negative signed integer value ever overflow? Put another way, can it be true that (mathematically) INT_MIN > -INT_MAX, LONG_MIN > -LONG_MAX etc? I know that typically it can't...
8
by: Polaris431 | last post by:
I have a buffer that holds characters. Four characters in a row represent an unsigned 32 bit value. I want to convert these characters to a 32 bit value. For example: char buffer; buffer =...
2
by: fredb | last post by:
I am trying to retrieve an integer value that is returned from an MS SQL function that our DBA wrote and is saved in a table in the database. Using the ODBC_EXEC command I am able to successfully...
6
by: phpmagesh | last post by:
Hai friends, {$PRODUCTS_PRICE} This is my variable i dont know why they used { } for that. in that product_price i m storing a integer value like 112.00 etc.., when i change to another radio...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.