Program.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. namespace Test
  3. {
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. Console.WriteLine("Hello World!");
  9. Console.WriteLine(validateMsisdn("+50935949762"));
  10. }
  11. public static String validateMsisdn(String input)
  12. {
  13. String CountryCode = "509";
  14. if (input == null || input.Length == 0)
  15. {
  16. return "";
  17. }
  18. if (input.StartsWith("+"))
  19. {
  20. input = input.Substring(1);
  21. }
  22. // check is number
  23. try
  24. {
  25. input = long.Parse(input) + "";
  26. }
  27. catch
  28. {
  29. return "";
  30. }
  31. //
  32. if (input.StartsWith("0"))
  33. {
  34. input = CountryCode + input.Substring(1);
  35. }
  36. else if (!input.StartsWith(CountryCode))
  37. {
  38. input = CountryCode + input;
  39. }
  40. return input.Trim();
  41. }
  42. }
  43. }