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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function for evaluating string data type

Status
Not open for further replies.

herci

Programmer
Nov 8, 2002
23
PA
hi everybody..
I would like to know if it exist any function in Java or Javascript that I can use to evaluate if a data is numeric or string..


thanks very much


 
you can test the value with regular expressions to see if the value for one can be converted to integer or is a string

if there are any characters other then digits in the value it will not convert to int correctly. you can also use
new string()
new Boolean()
parseFloat
parseInt

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924[/sub]
onpnt2.gif
 
You can use the isNaN() function to test if it is "Not A Number"

Adam
while(woman.width>woman.height && wallet.value>0){beer++;vision.blur()};
 
herci,

JavaScript is basically nontyped. You can check for the presence of certain characters in the string, but that means you have to decide what your rules are and then code to implement them. This depends on the purpose for which you are coding.

What do you think should be considered an "alpha" and what is a numeric? For example:

Code:
"3847598374956734985349857349085734905873098739087598364896387236458976348905726350324650237456027346508234608235603246502346532487563249732450834650364508732645086234508723450873645087634508763240872634087263450872634807236408726589724368972365087243650872346098234698235623457623508326405236.2000000000000000000000000000000000000000001"
"7.45.55"
"fourteen"
" 19 "
"(5)"
"6*4"
"!0------------0!"
"44!" (the result of the factorial operation on 44)
"4!" (the cry of a Hank Aaron fan)
"90210-4103" (a ZIP code)
"(206) 555-1212"
"123-45-6789" (a SSN)

Oooh, validation can be so fun!

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top