Basic Functions

Results 1 to 2 of 2

Thread: Basic Functions

  1. #1
    Join Date
    Dec 1969

    Default Basic Functions

    Some more Form Questions: <BR><BR>1) <BR>How do I check if the input given is alphanumerical. Meaning only a-z and 0-9? Is this not a standard JScript function? <BR>2) <BR>How do I check if the input give in only numerical. Meaning only 0-9? Is this not a standard JScript function? <BR>3) <BR>How do I turn a string into an Integer or Long in JScript. In VBScript its simple CInt and CLng. What is it in JScript? <BR><BR>Shelly, told me to read up on something, where? Can someone give a useful link or something else that I can really follow up on.

  2. #2
    Dan Evans Guest

    Default RE: Basic Functions

    I would guess she said regular expressions ( since they can be used to answer the first 2 questions. In fact, Q2 is even easier - JS has an isNaN (NaN = Not a Number) function:<BR><BR>var str = "123";<BR>alert(isNaN(str)); //Gives false for numbers, true for NaNs<BR><BR>Q1 can be done with a Reg Exp:<BR>var str = "123abc456";<BR>alert(!str.match(/W/g)) //Gives false when any non alphanumeric is present. Check the link above for details on why.<BR><BR>Q3. You can either use parseInt(str) which will make an int from the leading digits. In this case it would give 123 (discarding the abc456). Or you can use str - 0. The minus zero forces a conversion to an int. In this case str would become 0 since it&#039s not a number. "123" - 0 however would become 123 - 0.<BR><BR><BR>Hope this helps,<BR><BR>-Dan Evans

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts