The is
package provides a comprehensive set of validation functions for various data types commonly used in web applications, financial systems, and general software development. It offers a clean, efficient way to validate data formats ranging from basic types to complex financial and network identifiers.
Email(string) bool
- Email addressesNickname(string, ...bool) bool
- Usernames (with optional strict mode)VariableName(string, ...bool) bool
- Programming variable namesVariableNameFor(string, string) (bool, error)
- Language-specific variable names
BankCard(string, ...*regexp.Regexp) bool
- Credit/Debit card numbers with optional card type checkingIBAN(string, ...bool) bool
- International Bank Account NumbersIban(string, ...bool) bool
- Alias for IBAN validation
Latitude[T string|float64](T) bool
- Latitude coordinatesLongitude[T string|float64](T) bool
- Longitude coordinatesCoordinates[T string|float64](lat, lon T) bool
- Coordinate pairs
IPv4(string) bool
- IPv4 addressesIPv6(string) bool
- IPv6 addressesIP(string) bool
- Any IP address (v4 or v6)Phone(string) bool
- Phone numbersE164(string) bool
- E.164 format phone numbers
Alpha(string) bool
- Alphabetic charactersAlnum(string) bool
- Alphanumeric charactersDigit(string) bool
- Numeric digits onlyLower(string) bool
- Lowercase lettersUpper(string) bool
- Uppercase lettersTitle(string) bool
- Title case textSpace(string) bool
- Whitespace charactersNumeric(string) bool
- Numeric strings (including decimals)Decimal(string) bool
- Decimal numbersFloat(string) bool
- Floating-point numbers
Even[T Numerable](T, ...bool) bool
- Even numbersOdd[T Numerable](T, ...bool) bool
- Odd numbersWhole[T Numerable](T) bool
- Whole numbersNatural[T Numerable](T) bool
- Natural numbersPositive[T Numerable](T) bool
- Positive numbersNegative[T Numerable](T) bool
- Negative numbersZero[T Numerable](T) bool
- Zero value check
Base64(string) bool
- Base64 encodingBase64URL(string) bool
- URL-safe Base64 encodingHex(string) bool
- Hexadecimal stringsBin(string) bool
- Binary stringsHexColor(string) bool
- Hexadecimal color codesRGBColor(string) bool
- RGB color formatMD5(string) bool
- MD5 hash stringsJWT(string) bool
- JSON Web Tokens
IMEI[T string|int64](T) bool
- International Mobile Equipment IdentityIMSI(string) bool
- International Mobile Subscriber Identity
go get -u github.com/goloop/is
The package provides validation functions that do not pre-clean the data. If the validation data needs to be cleaned, it must be cleaned beforehand, for example, using the g package.
Example:
raw := "GB82 WEST 1234 5698 7654 32" // contains spaces
iban := g.Weed(raw, g.Whitespaces) // remove spaces
valid := is.IBAN(iban) // validate
package main
import (
"fmt"
"github.com/goloop/is"
)
func main() {
// Email validation.
fmt.Println(is.Email("user@example.com")) // true
fmt.Println(is.Email("invalid-email")) // false
// Phone number validation.
fmt.Println(is.Phone("+1 (234) 567-8900")) // true
fmt.Println(is.E164("+12345678900")) // true
// Geographic coordinates.
fmt.Println(is.Coordinates(51.5074, -0.1278)) // true
fmt.Println(is.Coordinates(91.0, 0.0)) // false
// Financial validation.
fmt.Println(is.BankCard("4111111111111111")) // true
fmt.Println(is.IBAN("DE89370400440532013000")) // true
}
package main
import (
"fmt"
"github.com/goloop/is"
)
func main() {
// Variable name validation for different languages.
fmt.Println(is.VariableNameFor("myVar", "go")) // true
fmt.Println(is.VariableNameFor("class", "python")) // false (reserved word)
// Strict mode validation.
fmt.Println(is.Nickname("user123", true)) // true
fmt.Println(is.Nickname("user@123", true)) // false
// Number validation.
fmt.Println(is.Even(4)) // true
fmt.Println(is.Natural(5)) // true
fmt.Println(is.Positive(-1)) // false
// Format validation.
fmt.Println(is.HexColor("#FF5733")) // true
fmt.Println(is.Base64("SGVsbG8=")) // true
fmt.Println(is.JWT("eyJhbGciOiJIUzI...")) // true
}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.