Documentation
¶
Overview ¶
Package misc contains some miscellaneous functions and constants that don't really fit elsewhere.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // EmailValidation (const) EmailValidation = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$") )
Functions ¶
func IsEmailValid ¶
IsEmailValid checks if the given email is valid using regex only.
Identical to the function found on this page: https://golangcode.com/validate-an-email-address/.
Example ¶
Check if the email:
test@example.com
Is valid and then check whether some normal text is valid.
// Valid example
e := "test@example.com"
if IsEmailValid(e) {
fmt.Println(e + " is a valid email")
}
// Invalid example
if !IsEmailValid("just text") {
fmt.Println("not a valid email")
}
Output: test@example.com is a valid email not a valid email
Types ¶
type Ordered ¶ added in v2.4.7
type Ordered int
func Compare ¶ added in v2.4.7
func Compare[V constraints.Ordered](a, b V) Ordered
Compare compares the two constraints.Ordered values and returns:
- Less: a < b
- Equal: a == b
- Greater: a > b
Example ¶
Compare some constraints.Ordered values!
fmt.Printf("Compare(1, 2) = %s\n", Compare(1, 2))
fmt.Printf("Compare(1.23, 1.23) = %s\n", Compare(1.23, 1.23))
fmt.Printf("Compare(\"world\", \"hello\") = %s\n", Compare("world", "hello"))
Output: Compare(1, 2) = Less Compare(1.23, 1.23) = Equal Compare("world", "hello") = Greater
Click to show internal directories.
Click to hide internal directories.