Skip to content

Helper Functions

tomolimo edited this page Nov 23, 2021 · 9 revisions

Some helper functions can be used in Formulas to ease field validations:
They have been added via a namespace: FVH

  1. FVH.isValidDate(d, t = false): d is a string which can be a date or a datetime. t is a boolean which if true will validate a datetime or false will validate a date only. The date format is retrieved from GLPI user profile. Returns true if d is a valid date, false otherwise. To be used with datepicker fields for example. Beware that if d is an empty string '' it will return true: empty string must be tested by a #!='' for example.
  2. FVH.isValidTime(s): returns true if s is a valid time, false otherwise.
  3. FVH.isValidInteger(i): returns true if i is a valid integer, false otherwise. If value is an empty string then returns false.
  4. FVH.countWords(s): returns the quantity of words in s. There is no condition on the size of each words.
  5. FVH.isValidIPv4(s): returns true if sis a valid IP V4 address, false otherwise
  6. FVH.isValidIPv6(s): returns true if sis a valid IP V6 address, false otherwise
  7. FVH.isValidMacAddress(s): returns true if s is a valid MAC address, false otherwise
  8. FVH.isValidEmail(s): returns true if s is a valid email address, false otherwise. Will use the input type=email if it exists (HTML5), otherwise will use a basic verification. Anyway, will verify that email address is valid, the check is only about format.

If you need more helper functions, please post an issue explaining your needs: https://github.com/tomolimo/formvalidation/issues

Clone this wiki locally