validator ‐ Utility For Data Confirmation - cobocombo/Scriptit-Core GitHub Wiki

Module to help validate data for common input scenarios.

Methods

  • isNumberInRange ({ number, min, max }): Method to checks if a number is within a specified range.
  • isStringEmpty ({ string }): Method to check if a string is empty or contains only whitespace.
  • isValidCreditCardNumber ({ cardNumber }): Method to validate a credit card number using the Luhn algorithm.
  • isValidDate ({ dateString }): Method to checks if a date string is valid and in the correct format (YYYY-MM-DD).
  • isValidEmail ({ email }): Method to checks if an email address is valid.
  • isValidPassword ({ password }): Method to checks if a password meets the following requirements: min 8 characters long, 1 uppercase letter, 1 lowercase letter, and 1 number.
  • isValidPhoneNumber ({ phoneNumber }): Method to check if a phone number is valid.
  • isValidUsername ({ username }): Method to check if a username is valid and meets the following requirements: min 3 characters long, max 16 characters long, no spaces, and no other special characters besides underscores.
  • isValidURL ({ url }): Method to checks if a website URL is valid.

Usage

validator.isNumberInRange({ number: 5, min: 0, max: 10 }) // Returns true.
validator.isNumberInRange({ number: 13, min: 0, max: 10 }) // Returns false.

validator.isStringEmpty({ string: '' }) // Returns true.
validator.isStringEmpty({ string: 'hello' }) // Returns false.