본문으로 건너뛰기

올바른 이메일 주소, 알파벳, 숫자 체크(Regexp)

Goa-zA-Z0-9?(?:\.a-zA-Z0-9?)$") return er.MatchString(email) }

/**

  • 알파뱃 , 숫자 체크 / func isAlphaNumString(str string) bool { match, _ := regexp.MatchString("^[a-zA-Z0-9$]+$", str) return match }" style=“color:#d8dee9ff;display:none” aria-label=“Copy” class=“code-block-pro-copy-button”>
    package main
    
    import (
    	"fmt"
    	"regexp"
    )
    
    func main() {
    	testMail := "example@example.com"
    	if isValidEmail(testMail) {
    		fmt.Println("올바른 이메일 주소")
    	} else {
    		fmt.Println("잘못된 이메일 주소")
    	}
    }
    
    // 이메일 검사
    func isValidEmail(email string) bool {
    	er := regexp.MustCompile("^[a-zA-Z0-9.!#$%&'+\/=?^_`{|}~-]+@a-zA-Z0-9?(?:\.a-zA-Z0-9?)$")
    	return er.MatchString(email)
    }
    
    /
    * 알파뱃 , 숫자 체크
    **/
    func isAlphaNumString(str string) bool {
    	match, _ := regexp.MatchString("^[a-zA-Z0-9$]+$", str)
    	return match
    }

이메일 주소를 입력 받을때 종종 필요한 .. 이메일 주소 유효성 검사 코드입니다.