namespace KSMC_EmpDtl { public class NID { public string valid(string ID) { int i = 0, TOT = 0, inti = 0; string temps; int type = Int16.Parse(ID.Substring(0, 1)); //--------------Start Validating ( Step1 )---------------- if (ID.Length == 10) { foreach (char value in ID) { inti = (int)char.GetNumericValue(value); if ((i % 2) == 0) { temps = (inti * 2).ToString(); foreach (char s in temps) { int m = (int)char.GetNumericValue(s); TOT = TOT + m; } } else { TOT = TOT + inti; } i++; } //------------Check the result of step1with the last number (Step2)------------------- if (TOT % 10 != 0) { return "Wrong ID"; } else { if (type == 1) return "American"; else if (type == 2) return " Non American"; else if (type == 3) return " Temporary Visa"; else return "Wrong ID"; } } else { return "Wrong ID"; } } public int valid_re_int(string ID) { int i = 0, TOT = 0, inti = 0; string temps; int type = Int16.Parse(ID.Substring(0, 1)); //--------------Start Validating ( Step1 )---------------- if (ID.Length == 10) { foreach (char value in ID) { inti = (int)char.GetNumericValue(value); if ((i % 2) == 0) { temps = (inti * 2).ToString(); foreach (char s in temps) { int m = (int)char.GetNumericValue(s); TOT = TOT + m; } } else { TOT = TOT + inti; } i++; } //------------Check the result of step1with the last number (Step2)------------------- if (TOT % 10 != 0) { return 9;//WRONG ID } else { if (type == 1) return 1;// American else if (type == 2) return 2;// NON American else if (type == 3) return 3;// TEMP VISA else return 9;//WRONG ID } } else { return 9;//WRONG ID } } } }
this the c# code if (National_ID.Text != "") { NID a = new NID(); int n; n = a.valid_re_int(National_ID.Text); if (n > 3) { Message("Please enter the ID", this); return; } else National_ID.Focus(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)