File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -41,3 +41,10 @@ func SplitString(n int, strs ...string) []string {
4141
4242return split
4343}
44+
45+ // ContainsSpecialChars checks for special characters.
46+ func ContainsSpecialChars (s string ) bool {
47+ isStringAlphabetic := regexp .MustCompile (`^[a-zA-Z0-9]*$` ).MatchString
48+
49+ return ! isStringAlphabetic (s )
50+ }
Original file line number Diff line number Diff line change @@ -77,3 +77,28 @@ func ExampleSplitString_other() {
7777fmt .Println (rstring .SplitString (- 1 , "mango is fruit" ))
7878// Output: [mango is fruit]
7979}
80+
81+ func TestContainsSpecialChars (t * testing.T ) {
82+ type test struct {
83+ input string
84+ result bool
85+ }
86+
87+ tests := []test {{input : "abc" , result : false }}
88+ chars := "!/*-+_@&$#%"
89+
90+ for _ , v := range chars {
91+ tests = append (tests , test {input : string (v ), result : true })
92+ }
93+
94+ for _ , tc := range tests {
95+ tc := tc
96+ t .Run (tc .input , func (t * testing.T ) {
97+ result := rstring .ContainsSpecialChars (tc .input )
98+ if result != tc .result {
99+ t .Errorf ("ContainsSpecialChars(%s) Failed: expected %+v, actual %+v" ,
100+ tc .input , tc .result , result )
101+ }
102+ })
103+ }
104+ }
You can’t perform that action at this time.
0 commit comments