File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -67,5 +67,32 @@ public static bool IsOnlyAsciiLetters(this string s)
6767
6868 return true ;
6969 }
70+
71+ /// <summary>
72+ /// Gets a flag indicating whether the string only consists of ASCII letters and numbers.
73+ /// </summary>
74+ /// <param name="s">The string to check.</param>
75+ /// <returns>True if the string only consists of ASCII letters, otherwise false.</returns>
76+ public static bool IsOnlyAsciiLettersAndNumbers ( this string s )
77+ {
78+ if ( string . IsNullOrEmpty ( s ) )
79+ {
80+ return true ;
81+ }
82+
83+ foreach ( char item in s )
84+ {
85+ if ( item is >= 'A' and <= 'Z' or >= 'a' and <= 'z' or >= '0' and <= '9' )
86+ {
87+ continue ;
88+ }
89+ else
90+ {
91+ return false ;
92+ }
93+ }
94+
95+ return true ;
96+ }
7097 }
7198}
Original file line number Diff line number Diff line change 66 </PropertyGroup >
77
88 <ItemGroup >
9+ <Using Include =" System.Diagnostics.CodeAnalysis" />
910 <Using Include =" Xunit" />
1011 </ItemGroup >
1112
You can’t perform that action at this time.
0 commit comments