Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

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 144 views
144 views asked Aug 7, 2020 by avibootz
2 answers 278 views
...