{"record":{"id":"6fb35cf7453fd498","repo":"TheAlgorithms/Go","slug":"cannot-contain-numbers-or-symbols","errorCode":null,"errorMessage":"Cannot contain numbers or symbols","messagePattern":"Cannot contain numbers or symbols","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"strings/isisogram.go","lineNumber":43,"sourceCode":"\tre := regexp.MustCompile(`\\d`)\n\treturn re.MatchString(text)\n}\n\nfunc hasSymbol(text string) bool {\n\tre := regexp.MustCompile(`[-!@#$%^&*()+]`)\n\treturn re.MatchString(text)\n}\n\nfunc IsIsogram(text string, order IsogramOrder) (bool, error) {\n\tif order < First || order > Third {\n\t\treturn false, errors.New(\"Invalid isogram order provided\")\n\t}\n\n\ttext = strings.ToLower(text)\n\ttext = strings.Join(strings.Fields(text), \"\")\n\n\tif hasDigit(text) || hasSymbol(text) {\n\t\treturn false, errors.New(\"Cannot contain numbers or symbols\")\n\t}\n\n\tletters := make(map[string]int)\n\tfor _, c := range text {\n\t\tl := string(c)\n\t\tif _, ok := letters[l]; ok {\n\t\t\tletters[l] += 1\n\n\t\t\tif letters[l] > 3 {\n\t\t\t\treturn false, nil\n\t\t\t}\n\n\t\t\tcontinue\n\t\t}\n\t\tletters[l] = 1\n\t}\n\n\tmapVals := make(map[int]bool)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/strings/isisogram.go#L25-L61","documentation":"IsIsogram only examines letters for repetition, so it rejects inputs containing digits or symbols (checked via hasDigit and a symbol regexp). If the cleaned text contains a digit or one of the supported symbols, it returns this error because an isogram check over such characters is not meaningful in this implementation.","triggerScenarios":"Calling IsIsogram with text containing digits (e.g. 'hello123') or symbols matching [-!@#$%^&*()+] (e.g. 'hydro!'). Hyphens are stripped as separators in some usage paths, but any other listed symbol triggers the error.","commonSituations":"Passing sentences with punctuation or hyphenated tokens without sanitizing; user input with digits; forgetting that the function lowercases and joins whitespace-separated fields but does not strip all symbols.","solutions":["Strip or reject digits and symbols from the text before calling IsIsogram","Pre-validate with the same checks (digits, symbol regexp) and handle the failure in your UI","Normalize input to letters-only (e.g. regexp [^a-z] removal after lowering) if your domain allows"],"exampleFix":"// before\nIsIsogram(\"six-year-old!\", isogram.First) // '!' is a symbol\n// after\ncleaned := regexp.MustCompile(`[^a-z]`).ReplaceAllString(strings.ToLower(s), \"\")\nIsIsogram(cleaned, isogram.First)","handlingStrategy":"validation","validationCode":"var symbolRe = regexp.MustCompile(`[-!@#$%^&*()+]`)\nfunc lettersOnly(s string) bool {\n    for _, r := range s {\n        if unicode.IsDigit(r) {\n            return false\n        }\n    }\n    return !symbolRe.MatchString(s)\n}\n// call IsIsogram only if lettersOnly(text)","typeGuard":"func isIsogramCandidate(s string) bool {\n    s = strings.ToLower(s)\n    for _, r := range s {\n        if unicode.IsDigit(r) {\n            return false\n        }\n    }\n    return !regexp.MustCompile(`[-!@#$%^&*()+]`).MatchString(s)\n}","tryCatchPattern":"ok, err := isogram.IsIsogram(text, order)\nif err != nil {\n    if strings.Contains(err.Error(), \"Cannot contain numbers or symbols\") {\n        // sanitize input and retry, or surface a friendly message\n    }\n    return err\n}","preventionTips":["Sanitize input to letters-only before calling IsIsogram","Mirror the library's digit and symbol checks in your own pre-validation so messages are consistent","Document that only letters participate in the isogram check"],"tags":["isogram","input-validation","strings"],"backgroundTag":"invalid-input-charset","analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}