isempty
Purpose: Checks whether the value being tested is empty. Return Values: A value is empty if:
Example:
Tip: The isempty() function should prove useful when you need to process user input from an HTML form. In most forms, there are some fields that can be left blank, and others that are required. Example:
Notice in the above example that we first made sure the ZipCode variable had a value assigned to it before doing any further validation checks. Had we omitted this test, heitml would have generated an error message when it tried to determine the length of a variable that had not previously been declared. Also note that our validation checks assume that we are using a five digit Zip Code instead of the newer Zip+4 format, which is why we tested for a length of 5 with the len() function. And, of course, U.S. Zip Codes contain only numbers, so if a User had entered something like "x0321", our real() function would not have been able to convert the string of characters contained within ZipCode to a numeric value. In both cases, our program would have recognized that an invalid Zip Code had been entered and printed the appropriate message. See Also: isdecl(). © 1996-2025 H.E.I. All Rights Reserved. |
![]() |