TheBulgarianWolf

Valid Usernames

Mar 18th, 2021
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace ValidUsernames
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter the usernames here: ");
  11.             string[] usernames = Console.ReadLine().Split(", ");
  12.             StringBuilder sb = new StringBuilder();
  13.             foreach(string username in usernames)
  14.             {
  15.                 bool check = true;
  16.                 if(username.Length < 3 || username.Length > 16)
  17.                 {
  18.                     check = false;
  19.                 }
  20.  
  21.                 foreach(char ch in username)
  22.                 {
  23.                     int code = (int)ch;
  24.                     if((code >= 48 && code <= 57) || (code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code == 45 || code == 95)
  25.                     {
  26.                         continue;
  27.                     }
  28.                     else
  29.                     {
  30.                         check = false;
  31.                     }
  32.                 }
  33.  
  34.                 if(check == true)
  35.                 {
  36.                     sb.Append(username + " ");
  37.                 }
  38.             }
  39.             string[] validUsernames = sb.ToString().Split(" ");
  40.             foreach(string valid in validUsernames)
  41.             {
  42.                 Console.WriteLine(valid);
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Add Comment
Please, Sign In to add comment