var loginRex = /^[.\-\a-zA-Z0-9]+$/i;
if(!loginRex.test(login)){
//обработаем ошибку валидации
}
package main
import (
"fmt"
"regexp"
)
func main() {
// Compile the expression once, usually at init time.
// Use raw strings to avoid having to quote the backslashes.
var validID = regexp.MustCompile(`^[a-z]+\[[0-9]+\]$`)
fmt.Println(validID.MatchString("adam[23]"))
fmt.Println(validID.MatchString("eve[7]"))
fmt.Println(validID.MatchString("Job[48]"))
fmt.Println(validID.MatchString("snakey"))
}
package validator
import "regexp"
const (
Email string = "^[\\w\\.\\d-_]+@[\\w\\.\\d-_]+\\.\\w{2,4}$"
Login string = "^[.\\-\\a-zA-Z0-9]+$"
)
var (
rxEmail = regexp.MustCompile(Email)
rxLogin = regexp.MustCompile(Login)
)
func IsEmail(str string) bool {
return rxEmail.MatchString(str)
}
func IsLogin(str string) bool {
return rxLogin.MatchString(str)
}