Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace ValidUsername
- {
- class Program
- {
- static void Main()
- {
- string[] usernames = Console.ReadLine().Split(", ");
- for (int i = 0; i < usernames.Length; i++)
- {
- string username = usernames[i];
- if (username.Length >= 3 && username.Length <= 16)
- {
- bool isValid = true;
- for (int j = 0; j < username.Length; j++)
- {
- if (!char.IsLetterOrDigit(username[j]) && username[j] != '-' && username[j] != '_')
- {
- isValid = false;
- break;
- }
- }
- if (isValid)
- {
- Console.WriteLine(username + " ");
- }
- }
- }
- }
- }
- }
- REGEX SOLUTION:
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace ValidUsername
- {
- class Program
- {
- static void Main()
- {
- string pattern = @"^[A-Za-z-_]{3,16}$";
- var usernames = Console.ReadLine().Split(", ");
- for (int i = 0; i < usernames.Length; i++)
- {
- if (Regex.IsMatch(usernames[i], pattern))
- {
- Console.WriteLine(usernames[i]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement