Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use of isNumeric

Status
Not open for further replies.

evillin

Technical User
Jan 2, 2004
20
GB
Very grateful for anyone's thoughts on the below.

I want to look at a field entry (OtherPhone field) in a database and check if the entry is numeric. If it is numeric i want to print the contents of the field with a 6 in front of it. If not numeric i just want to print the contents of the field.

Am getting a syntax error - can anyone see where im going wrong? Many thanks for your time...

CODE

if isNumeric((objRS("OtherPhone")) then
Response.write "<tr><td><b>Other Phone: </b>6" & objRS("OtherPhone")
Response.write "</td></tr>"
else
Response.write "<tr><td><b>Other Phone: </b>" & objRS("OtherPhone")
Response.write "</td></tr>"
end if



 
>if isNumeric((objRS("OtherPhone")) then
[tt]
if isNumeric((objRS("OtherPhone"))[red])[/red] then
[/tt]
 
Are you sure that you are getting a Number(ish) data type back from the RS and not a string ? You may have to convert it to a number instead and trap errors or use a Regular Expression.
 
thanks both of you - even with the syntax fix there is no error but it doesnt work so i suspect as you say ggriffit, I'm not getting a number back. Are you able to help with more detail on how to 'convert it to a number instead and trap errors or use a Regular Expression'?

thankyou!
 
It's just occurred to me that isNumeric is not correct - really i want to check if there is a string with numbers in it not letters or null. For example, the field could contain nothing, a 4 digit number as a string, the letters N/A or the word NONE. If it's a 4 digit number as a string i want to put a 6 in front of it - else do nothing.
 
evillin,

Isnumeric can still be used. Try this?
[tt]
if isNumeric((objRS("OtherPhone"))) and len(trim(objRS("OtherPhone")))=4 then
[/tt]
But this assumes you have enough been policing the recordset data entry. (105.1 will have length 5 etc.) You don't want to validate entries at this time, or do you?!

- tsuji
 
tsuji - thanks but doesn't work.

Also Just tried -
othPhone = trim(objRS("OtherPhone"))
othPhone2 = Left(othPhone,1)
if othPhone2 = [0-9] then
Response.write "<tr><td><b>Other Phone: </b>6" & objRS("OtherPhone")
Response.write "</td></tr>"
else
Response.write "<tr><td><b>Other Phone: </b>" & objRS("OtherPhone")
Response.write "</td></tr>"
end if

doesn't work. Sigh.
 
evillin,

It may not be sufficiently filtering out cases, it may not be perfect,... but, it doesn't work??? at all. I do not get it.

- tsuji
 
This line:
Code:
 if othPhone2 = [0-9] then
cannot work, as far as I know. There's a fine place to use IsNumeric, though:
Code:
 If IsNumeric(othPhone2) Then
or simply eliminate othPhone2 and use
Code:
If IsNumeric(Left(othPhone,1)) Then
 
I've found better results of the IsNumeric function if you use the full syntax of:

If IsNumeric(variable) = true then
blah blah
end if

true for numeric, false for not numeric
 
Many thanks everyone for your help and useful advice- have now resolved and got isNumeric working properly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top