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 *** 11 3711
"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
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.
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 ***
"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
> 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
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.
> 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.
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.
> 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.
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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",...
|
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,...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |