Advertisement
okanfeim

Untitled

Apr 27th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace EgnValidating
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Please enter EGN !");
  14.             CheckEGN();
  15.         }
  16.         static void CheckEGN()
  17.         {
  18.             string EGN = Console.ReadLine();
  19.             if (EGN.Any(Char.IsSymbol) || EGN.Length != 10 || EGN.Any(Char.IsLetter))
  20.             {
  21.                 Console.WriteLine("Invalid format.EGN must contain only digits ! ");
  22.             }
  23.             else
  24.             {
  25.                 string yy = EGN.Substring(0, 2);
  26.                 string mm = EGN.Substring(2, 2);
  27.                 string dd = EGN.Substring(4, 2);
  28.                 if (int.Parse(mm) > 31)
  29.                 {
  30.                     yy = "20" + yy;
  31.                     mm = (int.Parse(mm) - 40).ToString();
  32.                 }
  33.                 else if (int.Parse(mm) > 20 && int.Parse(mm) < 31)
  34.                 {
  35.                     yy = "18" + yy;
  36.                     mm = (int.Parse(mm) - 20).ToString();
  37.                 }
  38.                 else
  39.                 {
  40.                     yy = "19" + yy;
  41.                 }
  42.                 Console.WriteLine("Valid EGN format");
  43.  
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement