How to check if a string contains only English letters in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"regexp"
)

func isOnlyEnglishLetters(s string) bool {
	pattern := `^[a-zA-Z]+$`
	
	re := regexp.MustCompile(pattern)
	
	return re.MatchString(s)
}

func main() {
	s1 := "Golang"
	fmt.Println(isOnlyEnglishLetters(s1))

	s2 := "Golangゴーラング"
	fmt.Println(isOnlyEnglishLetters(s2))
}



/*
run:

true
false

*/

 



answered Dec 31, 2024 by avibootz

Related questions

...