![]() |
| ||
| Data Type Hi There. I'm new in java script , and I want to know somthing in it. I'm asking if i have a variable and i want to know the data type for the data in it. I'm not sure if you understand me well , but i will give you an example: If I have a variable named X , and this virable hold some data , how can I know the Type for that data (int , char , bool , float , .......). and if poseple show me that in example. thank you. mosh. |
| ||
| Re: Data Type As u know that we declare variable in Java Script using var now Im not sure if u want to static cast the variable or what but if thats the case u can do the following var Num = parseFloat(document.frmFormName.TextBoxName.value); |
| ||
| Re: Data Type Adding to that!!!! JavaScript are loosely typed, which means that the programmer does not need to specify the type of data that a variable will store when the programmer declares it, The language automaticaly adjust the variable's storage space to conform to the data values that the programmer assign to it, so A loosely Typed language automaticaly converts a variable to the correct data type within commands that perfoms operations such as adding two values |
| ||
| Re: Data Type > If I have a variable named X , and this virable hold some data , how can I know > the Type for that data The typeof operator should make things a bit easier for you. Try this: <script type="text/javascript"> |
| ||
| Re: Data Type Hi There. ~s.o.s~ & Traicey Thank you , what ~s.o.s~ write is the nearest of what i want. all i want is to know the type of data that entered by user. for example if the user input was string , then give him a message that the type is unacceptable. |
| ||
| Re: Data Type Quote:
If you're taking your input from a form, it will always be of type "string". What you probably want is to know what the string contains and if the range of characters are acceptable. You'd want to use some regular expression matching: <script> here is docs on the search method for strings. The regex for checking is string is a number is: /^[0-9]+$/ This makes sure all the characters given are numbers [0-9] from start (^) to finish ($). You can do the same for alphabetic characters: /^[a-z]+$/i All characters are alphabetic from[ a-z] while ignoring case (/i). Or put the two together: /^[0-9a-z]+$/i or add a few other allowed characters: /^[0-9a-z_-\s]+$/i which allows the _ character, the - character and the space character \s. Heres an example with those put together: var str = '24s'; You can also do: eg: // we want a number for ints and floats.. |
| All times are GMT -4. The time now is 5:31 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC