How to validate email address with regular expression in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"regexp"
)

func main() {
	s1 := "av!~@@email.com"
	s2 := "abc@email.com"
	s3 := "xyz@email"
	s4 := "uvw@email.collectivesolver"

	re := 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])?)*$")


	fmt.Printf("%v :%v\n", s1, re.MatchString(s1))
	fmt.Printf("%v :%v\n", s2, re.MatchString(s2))
	fmt.Printf("%v :%v\n", s3, re.MatchString(s3))
	fmt.Printf("%v :%v\n", s4, re.MatchString(s4))
}




/*
run:

av!~@@email.com :false
abc@email.com :true
xyz@email :true
uvw@email.collectivesolver :true

*/

 



answered Aug 14, 2020 by avibootz

Related questions

1 answer 167 views
167 views asked Aug 7, 2020 by avibootz
2 answers 306 views
...