zaryana

Registration

Mar 26th, 2020
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace _02_Registration
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string pattern = @"^[U][$](?<username>[A-Z][a-z]{2,})[U][$].*?[P][@][$](?<password>[A-Za-z]{5,}[A-Za-z0-9]*?\d)[P][@][$]$";
  14.  
  15.             int n = int.Parse(Console.ReadLine());
  16.             int validRegCount = 0;
  17.  
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 string regInput = Console.ReadLine();
  21.  
  22.                 Match match = Regex.Match(regInput, pattern);
  23.  
  24.                 if (match.Success)
  25.                 {
  26.                     Console.WriteLine($"Registration was successful");
  27.                     Console.WriteLine($"Username: {match.Groups["username"].Value}, Password: {match.Groups["password"].Value}");
  28.                     validRegCount++;
  29.                 }
  30.                 else
  31.                 {
  32.                     Console.WriteLine($"Invalid username or password");
  33.                 }
  34.             }
  35.             Console.WriteLine($"Successful registrations: {validRegCount}");
  36.         }
  37.     }
  38. }
Add Comment
Please, Sign In to add comment