(Last Updated 9/7/98)



Java Script Conditional Utilities



The following is a small set of utilities to expand the standard Java Script conditional checks. It includes: "isIn(x,y)", "IsNum(x)", "isLetter(x)", and "isAlpha(x)".

  • "isIn(x,y)" is a Boolean function that returns "true" if x is a substring of y and false any other time. Case is ignored and all arguments are treated as strings in this routine.

  • "isNum(x)" is a Boolean function that returns "true" if x is a number and false if not. One reason this function is needed is the built in function "isNan()" is only defined on UNIX platforms. The argument x is input to the routine as a string. The function only works for integers. (i.e. The decimal in a floating point number evaluates as false. A similar statement may be made for E formatted numbers. White-space is not ignored. (i.e. Spaces evaluate to false.)

  • "isLetter(x)" is a Boolean function that returns "true" if x is a alphabetic string or character and false if not. As with the previous routine, white space is NOT ignored at present.

  • "isAlpha(x)" is a Boolean function that returns "true" if x is a alpha-numeric string and false if not. Again white space is NOT ignored at present.


  • To use the utilities in a page, put file "Library.js" in the same directory as the page and insert: <SCRIPT SRC="Library.js"> </SCRIPT> in the page header. An example of its use in any script would then be:
    if (function) { statement block if true } else { statement block if false},
    where function is any of the functions above. Grab the FILE.

    I very rarely affix a copyright header to scripts but I have to this one. The script is freeware and may be used by anyone as long as the header remains intact with the code.

    Utility Checker


    isIn(x,y) Check if String in Data Element 1 (x) is contained within String in Data Element 2 (y).
    isLetter(x) Check if data in Data Element 1 (x) is alphabetic.
    isNum(x) Check if data in Data Element 1 (x) is numeric.
    {Note: isNan is only defined for UNIX platforms.}
    isAlpha(x) Check if data in Data Element 1 (x) is alpha-numeric.

    Data Element 1:
    Data Element 2:



    Results of check

    Data Element 3:




    Contact Carl Paulson with questions,
    or Visit my pages.