package main import ( "fmt" "regexp" ) func IsValidPhoneEmail(value interface{}) bool { var ( phonePattern string = `^\+?[0-9]\d{1,20}$` emailPattern string = `^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-]+)(\.[a-zA-Z]{2,5}){1,2}$` ) if isPhoneMatch, _ := regexp.MatchString(phonePattern, fmt.Sprintf("%v", value)); isPhoneMatch { return true } else if isEmailMatch, _ := regexp.MatchString(emailPattern, fmt.Sprintf("%v", value)); isEmailMatch { return true } return false } func main() { // pattern := `^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-]+)(\.[a-zA-Z]{2,5}){1,2}$` // data := "jamal13@gmail.com" isMatch := IsValidPhoneEmail(nil) fmt.Println(isMatch) } // improved ^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-]+)(\.[a-zA-Z]{2,5}){1,2}$const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;function validateEmail(email) { const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); }[a-zA-Z0-9_\.\+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-\.]+const emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/// This is by far the best regex used for email ^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$ //will validate for: test@gmail.com etcpattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{1,63}$" 1) js var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; 2) using in angular ng-pattern="mailformat" [a-zA-Z0-9._-]{3,}@[a-zA-Z0-9.-]{3,}\.[a-zA-Z]{2,4}