This repository contains JavaScript functions for validating various types of strings. Each function takes a string as input and returns true
if the string is valid, and false
otherwise.
containsOnlyLetters(str)
: Checks if a string contains only letters (uppercase and lowercase)isValidEmail(email)
: Checks if a string is a valid email addressisValidUrl(url)
: Checks if a string is a valid URLcontainsOnlyNumbers(str)
: Checks if a string contains only numbersisValidPhoneNumber(phoneNumber)
: Checks if a string is a valid phone numbercontainsOnlyAlphanumeric(str)
: Checks if a string contains only alphanumeric charactersisValidUsername(username)
: Checks if a string is a valid username (3-16 characters, letters and numbers only)isValidPassword(password)
: Checks if a string is a valid password (8-20 characters, at least one uppercase letter, one lowercase letter, and one number)isValidCreditCardNumber(creditCardNumber)
: Checks if a string is a valid credit card number (Visa, MasterCard, American Express, and Discover)isValidDate(date)
: Checks if a string is a valid date in the format YYYY-MM-DDisValidTime(time)
: Checks if a string is a valid time in the format HH:MM:SSisValidZipCode(zipCode)
: Checks if a string is a valid US zip code (5 digits)isValidStateAbbreviation(stateAbbreviation)
: Checks if a string is a valid US state abbreviation (2 uppercase letters)isValidIPv4Address(ipv4Address)
: Checks if a string is a valid IPv4 addressisValidIPv6Address(ipv6Address)
: Checks if a string is a valid IPv6 addressisValidMacAddress(macAddress)
: Checks if a string is a valid MAC addressisValidHexColorCode(hexColorCode)
: Checks if a string is a valid hexadecimal color code (e.g. #FFFFFF or #000000)isValidRgbColorCode(rgbColorCode)
: Checks if a string is a valid RGB color code (e.g. rgb(255,255,255))isValidCssColorCode(cssColorCode)
: Checks if a string is a valid CSS color code (e.g. red, #FFFFFF, rgb(255,255,255))isValidSlug(slug)
: Checks if a string is a valid slug (lowercase letters, numbers, and hyphens only)isValidUuid(uuid)
: Checks if a string is a valid UUID (version 1, 3, 4, or 5)