NMDanny

Strings T3

Jan 22nd, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.46 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 ConsoleApplication23
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Type an E-Mail address");
  14.             string Address = Console.ReadLine().ToLower();
  15.             int Valid = 1;
  16.             int Israel=0;
  17.             for (int i = 0; i < Address.Length; ++i)
  18.             {
  19.                 if (Address.IndexOf('@') > 0) // בדיקה אם יש שטרודל באימייל
  20.                 { }
  21.                 else
  22.                 { Valid = 0; }
  23.                 if (Address.IndexOf('.') == 0||Address.IndexOf('.')<=Address.IndexOf('@')+1) // בדיקה אם יש נקודה, והאם הנקודה באה אחרי השטרודל
  24.                 {
  25.                     Valid = 0;
  26.                 }
  27.                 if(Address.Length-1==Address.IndexOf('.'))   // בדיקה שיש משהו אחרי הנקודה על ידי בדיקה שהאימייל לא נגמר בנקודה
  28.                 {
  29.                     Valid=0;
  30.                 }
  31.                 if(Address.IndexOf(".il")>0) // בודק אם הכתובת ישראלית
  32.                 {
  33.                     Israel = 1;
  34.                 }
  35.  
  36.             }
  37.             if(Valid==1)
  38.             {
  39.  
  40.             for (int i = 0; i < Address.IndexOf('@'); ++i)    // בדיקת המחרוזת עד השטרודל
  41.             {
  42.                 if ((Address[i] >= 'a') && (Address[i] <= 'z'))         // בדיקה אם האותיות הן אנגליות
  43.                 { }
  44.                 else if ((Address[i] >= '0') && (Address[i] <= '9')) // אם לא, בדיקה אם הן מספרים
  45.                 { }
  46.                 else
  47.                 { Valid = 0; } // אם לא, הכתובת לא מתאימה
  48.             }
  49.  
  50.             for (int i = Address.IndexOf('@')+1; i < Address.IndexOf('.'); ++i)    // בדיקת המחרוזת מהשטרודל עד הסיומת
  51.             {
  52.                 if ((Address[i] >= 'a') && (Address[i] <= 'z'))         // בדיקה אם האותיות הן אנגליות
  53.                 { }
  54.                 else if ((Address[i] >= '0') && (Address[i] <= '9')) // אם לא, בדיקה אם הן מספרים
  55.                 { }
  56.                 else
  57.                 { Valid = 0; } // אם לא, הכתובת לא מתאימה
  58.  
  59.  
  60.             }
  61.             for (int i = Address.IndexOf('.') + 1; i < Address.Length; ++i)    // בדיקת הסיומת של האימייל
  62.             {
  63.                 if ((Address[i] >= 'a') && (Address[i] <= 'z'))         // בדיקה אם האותיות הן אנגליות
  64.                 { }
  65.                 else if ((Address[i] >= '0') && (Address[i] <= '9')) // אם לא, בדיקה אם הן מספרים
  66.                 { }
  67.                 else if (Address[i] == '.')           // בודק אם יש עוד סיומת לדוגמא co.il
  68.                 { }
  69.                 else
  70.                 { Valid = 0; } // אם לא, הכתובת לא מתאימה
  71.  
  72.  
  73.             }
  74.  
  75.              }
  76.             if (Valid == 1)
  77.             {
  78.                 Console.WriteLine("Email is valid");
  79.                 if (Israel == 1)
  80.                 {
  81.                     Console.WriteLine("Email is Israeli");
  82.                 }
  83.             }
  84.             else
  85.             {
  86.                 Console.WriteLine("Email is invalid");
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment