public static Tuple <bool, String> validateEmail(String email) { if (email.Length < 6) { return(new Tuple <bool, String>(false, "Email contain atleast 10 characters!")); } if (!email.All(Char.IsLetter)) { return(new Tuple <bool, String>(false, "Email must contain @!")); } String p = "Email can only contain lower case letters, numbers and '_', '.', '@'"; if (!email.All(c => Char.IsLetterOrDigit(c) || c == '_' || c == '.' || c == '@')) { new Tuple <bool, String>(false, p); } if (!email.Any(char.IsUpper)) { new Tuple <bool, String>(false, p); } if (!email.Any(char.IsNumber)) { new Tuple <bool, String>(false, p); } return(new Tuple <bool, String>(true, "Email is valid")); }
public static double CalculateFromFile() { double sum = 0; using (StreamReader reader = new StreamReader("salaries.txt")) { while (!reader.EndOfStream) { string tempLine; tempLine = reader.ReadLine(); if (!String.IsNullOrEmpty(tempLine) && tempLine.Length >= 2) { tempLine = tempLine.Trim(); Char firstChar = tempLine[0]; //first char String numbers = tempLine.Substring(1, tempLine.Length - 1); //rest of the values if (firstChar == 'G' && numbers.All(char.IsDigit)) { double netoSalary = CalculateNetoSalary(numbers); if (netoSalary > 0) { sum = sum + netoSalary; } } else if (firstChar == 'N' && numbers.All(char.IsDigit)) { sum = sum + Convert.ToDouble(numbers); } } } } return(sum); }
public static string CalculateFromFile(string tempLine) { if (!String.IsNullOrEmpty(tempLine) && tempLine.Length >= 2) { tempLine = tempLine.Trim(); Char firstChar = tempLine[0]; //first char String numbers = tempLine.Substring(1, tempLine.Length - 1); //rest of the values if (firstChar == 'G' && numbers.All(char.IsDigit)) { double netoSalary = CalculateNetoSalary(numbers); return(netoSalary.ToString()); } else if (firstChar == 'N' && numbers.All(char.IsDigit)) { return(numbers); } else { return("invalid"); } } else { return("invalid"); } }
/** * Method to filter data by property and value * Again, this is using Abstraction to hide the internal working from user **/ public List <Employee> GetFilteredData(int property, String value) { switch (property) { case 0: if (!value.All(Char.IsDigit)) { throw new Exception("Invalid value"); } return(FilterEmployeesByBirthday(Convert.ToInt32(value))); case 1: if (!value.All(Char.IsDigit)) { throw new Exception("Invalid value"); } return(GetEmployeeWithNthHighestSalary(Convert.ToInt32(value))); case 2: return(GetEmployeesByCityName(value)); default: return(this.Employees); } }
public bool zipCodeTest(String zipCode) { bool allDigits = zipCode.All(char.IsDigit); if (zipCode.All(char.IsDigit) == true && zipCode.Length == 5) { return(true); } else { return(false); } }
public void btnSearchEmployee_Click(object sender, EventArgs e) { lbEmployees.Items.Clear(); String input = tbSearchEmployee.Text; bool isText = input.All(char.IsLetter); bool isNum = input.All(char.IsDigit); String isEmpty = ""; try { if (input == isEmpty) { List <Employee> empList = dh.GetEmployees(); foreach (Employee emp in empList) { lbEmployees.Items.Add(emp.ToAString()); } } else if (isText == true) { List <Employee> empList = dh.GetEmployees(input); foreach (Employee emp in empList) { lbEmployees.Items.Add(emp.ToAString()); } } else if (isNum == true) { List <Employee> empList = dh.GetEmployees(Convert.ToInt32(input)); foreach (Employee emp in empList) { lbEmployees.Items.Add(emp.ToAString()); } } else if (input == isEmpty) { List <Employee> empList = dh.GetEmployees(); foreach (Employee emp in empList) { lbEmployees.Items.Add(emp.ToAString()); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
internal static Boolean SplitTFM(String tfm, out FrameworkIdentifiers identifier, out Version version) { identifier = FrameworkIdentifiers.Unsupported; version = null; if (!String.IsNullOrWhiteSpace(tfm)) { String _tfm = tfm.Trim().ToLower(); String _identifier = String.Concat(_tfm.TakeWhile(Char.IsLetter)); String _version = _tfm.Substring(_identifier.Length); identifier = _identifier switch { "netstandard" => FrameworkIdentifiers.NETStandard, "netcoreapp" => FrameworkIdentifiers.NETCoreApp, "net" => _version.Contains('.') ? FrameworkIdentifiers.NETCoreApp : FrameworkIdentifiers.NETFramework, _ => FrameworkIdentifiers.Unsupported, }; if (identifier != FrameworkIdentifiers.Unsupported && _version.All(c => Char.IsDigit(c) || c == '.')) { if (!Version.TryParse(_version, out version)) { version = new Version(String.Join(".", _version.Select(c => c.ToString()))); } } } return(Enum.IsDefined(typeof(FrameworkIdentifiers), identifier) && version != null); }
public static bool IsValidFolderName(String name) { Contract.Requires(!String.IsNullOrWhiteSpace(name)); // check system names if (String.IsNullOrWhiteSpace(name) || name == "." || name == "..") { return(false); } // whitespace and the start or end not allowed if (name[0] == WhiteSpace || name[name.Length - 1] == WhiteSpace) { return(false); } // max length if (name.Length > QuickIOPath.MaxFolderNameLength) { return(false); } // point at the beginning or at the end is not allowed // windows would automatically remove the point at the end if (name[0] == '.' || name[name.Length - 1] == '.') { return(false); } return(name.All(IsValidFolderChar)); }
//Displays menu and options public static int Menu() { Console.WriteLine("\nMAIN MENU\n"); int chc = 0; while (chc < 1 || chc > 4) { Console.WriteLine("\t(1) Enter Manager Menu"); Console.WriteLine("\t(2) Enter Customer Menu"); Console.WriteLine("\t(3) View Reports"); Console.WriteLine("\t(4) Exit Program"); Console.WriteLine("\nEnter number to select option: "); String input = Console.ReadLine(); if (input.All(char.IsNumber)) { chc = int.Parse(input); if (chc < 1 || chc > 4) { Console.WriteLine("Error: Enter value between 1 and 4"); } } else { Console.WriteLine("Error: Enter only numeric values"); } } return(chc); }
public JsonResult Register(String personId, String Id) { string formError = string.Empty; var pin = User.Identity.Name.Split('\\')[1]; bool IsOrganizer = false; try { if (!string.IsNullOrEmpty(personId) && !string.IsNullOrEmpty(Id)) { int prsnId = Convert.ToInt32(personId); int eventId = Convert.ToInt32(Id); // validate and fetch event if ((prsnId > 0) && Id.All(char.IsNumber)) { EventViewModel evnt = EventViewModel.CreateViewModel(_service.GetEventByUID(eventId)); foreach (var organizerPin in evnt.Organizers) { if (!IsOrganizer) { IsOrganizer = (pin == organizerPin) ? true : false; } } if (evnt != null) { if (_service.IsRegister(eventId, prsnId)) { formError = "User already Registered"; } else { formError = _service.Register(eventId, prsnId, IsOrganizer); } } else { formError = "Cannot find the event specified, please try again and make sure you have a valid event"; } } else { formError = "Person couldn't be found"; } } else { formError = "UserID field cannot be empty"; } } catch (Exception ex) { formError = "Oops, something went wrong"; } return(Json( new { status = string.IsNullOrEmpty(formError) ? "success" : "error", message = formError })); }
private bool ValidateDataInput() { bool bValidate = true; Control[] f = { txtGas92NewPrice, txtGas95NewPrice, txtGasDONewPrice }; for (int i = 0; i < f.Length; i++) { String txt = f[i].Text.Trim(); SGMHelper.ShowToolTip(f[i], ""); if (txt.Equals("")) { SGMHelper.ShowToolTip(f[i], SGMText.UPDATE_PRICE_INPUT_NULL); bValidate = false; break; } if (!txt.All(Char.IsDigit) || Int32.Parse(txt) < 0) { SGMHelper.ShowToolTip(f[i], SGMText.UPDATE_PRICE_INPUT_ERR); bValidate = false; break; } } return(bValidate); }
static void Main(string[] args) { Console.WriteLine("Please enter a day of the week"); Start: String Answer = Console.ReadLine(); Days input; try { if (Answer.All(char.IsDigit)) { throw new Exception(); } input = (Days)Enum.Parse(typeof(Days), Answer); } catch (Exception a) { Console.WriteLine("Please enter an actual day of the week."); goto Start; } Console.WriteLine("Good Job"); Console.ReadLine(); }
private void textBox3_TextChanged(object sender, EventArgs e) { String str = textBox3.Text; if (str.All(char.IsDigit)) { textBox3.BackColor = Color.LightGreen; b3 = true; pictureBox8.Image = global::AleksandarBosnjak.Properties.Resources._3_g; } else { textBox3.BackColor = Color.IndianRed; pictureBox8.Image = global::AleksandarBosnjak.Properties.Resources._3; b3 = false; } if (str == "") { textBox3.BackColor = Color.White; pictureBox8.Image = global::AleksandarBosnjak.Properties.Resources._3; b3 = false; } if (sviOdradjeni()) { button2.Enabled = true; } else { button2.Enabled = false; } /*b3 = true; * pictureBox8.Image = global::AleksandarBosnjak.Properties.Resources._3_g;*/ }
/* * Validates that password is a strong password * Conditions: * Special characters not allowed * Spaces not allowed * At least one number character * At least one capital character * Between 6 to 12 characters in length */ public static bool isStrongPassword(String password) { // Check for null if (password == null) { return(false); } // Minimum and Maximum Length of field - 6 to 12 Characters if (password.Length < passwordLowerBoundary || password.Length > passwordUpperBoundary) { return(false); } // Special Characters - Not Allowed // Spaces - Not Allowed if (!(password.All(c => char.IsLetterOrDigit(c)))) { return(false); } // Numeric Character - At least one character if (!password.Any(c => char.IsNumber(c))) { return(false); } // At least one Capital Letter if (!password.Any(c => char.IsUpper(c))) { return(false); } return(true); }
private void AddBalanceButton_Click(object sender, EventArgs e) { if (textBoxNumber.TextLength == 0 || textBoxBalance.Text.Length == 0) { MessageBox.Show("We need values in ALL the empty boxes"); } else { try { String number = textBoxNumber.Text; String balance = textBoxBalance.Text; Account account = MyController.FindAccount(number); if (MyController.IsAccountEmpty(account)) { MessageBox.Show("Theres no account with that number, try to add it first."); } else if (balance.All(char.IsDigit)) { MyController.AddBalanceInAccount(account, Int32.Parse(balance)); MessageBox.Show("The balance was added to the account."); GoToFirstInterface(MyController); } else { MessageBox.Show("The amount to add in balance should be in number."); } } catch (LogicException exMessage) { MessageBox.Show(exMessage.Message); } } }
private static Boolean IsSuitableForHashtag(String word) { return (Char.IsLetter(word[0]) && word.All(IsSuitableForHashtag)); }
public static String[] SplitAndTrim(this String value, params String[] separators) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if ((value.Length == 0) || value.All(Char.IsWhiteSpace)) { throw new ArgumentException(Resources.ErrorStringEmpty, nameof(value)); } if (separators == null) { throw new ArgumentNullException(nameof(separators)); } if (separators.Length == 0) { throw new ArgumentException(Resources.ErrorStringSeparators, nameof(separators)); } String[] valueChunks = value.Split(separators, StringSplitOptions.RemoveEmptyEntries); return(Array.ConvertAll(valueChunks, x => x.Trim())); }
public static IWebElement Set(this IWebElement webElement, String text, bool force = false) { if (webElement.TagName == "select") { var dropdown = new SelectElement(webElement); dropdown.SelectByValue(text); if (string.IsNullOrWhiteSpace(dropdown?.SelectedOption?.Text)) { dropdown.SelectByText(text); } if (string.IsNullOrWhiteSpace(dropdown?.SelectedOption?.Text)) { dropdown.SelectByText(text, true); } if (text.Any() && text.All(Char.IsDigit) && string.IsNullOrWhiteSpace(dropdown?.SelectedOption?.Text)) { dropdown.SelectByIndex(Convert.ToInt32(text)); } } else { var formatedText = text.Replace("\r\n", "\n").Replace("\r", "\n") .Replace("\n", Keys.Shift + Keys.Enter + Keys.Shift); webElement.Clear(); webElement.TypeKeys(formatedText); } return(webElement); }
//Create a user-determined site from a template and adds it to siteLibrary and SourceItems list private void CircleText_KeyDown(object sender, KeyEventArgs e) { try { if (e.Key == Key.Return) { String siteSeq = CircleText.Text; Boolean isNotDupe = true; foreach (Sites site in pd2.FusionSiteLibrary) { if (siteSeq == site.Sequence) { isNotDupe = false; } } if (siteSeq.All(c => "actg".Contains(c)) && siteSeq.Length < 5 && isNotDupe && siteSeq != "aatg") //aatg can only be used between RBS and CDS so they shouldn't need it in the library as a drag and droppable Site { Point originalCenter = Center; Sites s = new Sites(siteSeq); s.Center = originalCenter; pd2.PD2_siteLibrary.Items.Add(s); pd2.FusionSiteLibrary.Add(s); pd2.PD2_siteLibrary.Items.Remove(this); } } } catch (Exception exc) { Console.WriteLine(exc); } }
public HashSet <String> GenerateAllPhoneWords(String phoneNumber) { bool isNumber = phoneNumber.All(char.IsDigit); List <string> possibleWords = null; HashSet <string> generatedWords = new HashSet <string>(); if (isNumber) { possibleWords = GenerateWords(phoneNumber, null); } else { return(null); } if (possibleWords != null) { foreach (var word in possibleWords) { if (_dictionary.Contains(word)) { generatedWords.Add(word); } } } return(generatedWords); }
/// <summary> /// Chequea que el string solo contenga digitos; /// </summary> /// <param name="value">String a chequear</param> /// <exception cref="ExcepcionesSKD.InformacionPersonalInvalidaException"> /// Si el el valor contiene algún caracter que no sea dígito. /// </exception> private void CheckDigits(String value) { if (!value.All(char.IsDigit)) { throw new InformacionPersonalInvalidaException("La información de Telefono solo deben ser digitos."); } }
public List <EquipmentForRbi> getListEQForRBI(String path) { List <EquipmentForRbi> list = new List <EquipmentForRbi>(); OleDbConnection conn = getConnect(path); try { conn.Open(); String cmd = "select * from [Totals$]"; OleDbCommand command = new OleDbCommand(cmd, conn); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { String data = reader[0].ToString(); if ((data != "") && (data.All(char.IsDigit))) { eq = new EquipmentForRbi(); eq.UnitCode = data; eq.UnitName = reader[1].ToString(); eq.ProcessSystem = reader[2].ToString(); list.Add(eq); } } } catch { MessageBox.Show("Please Check Version Excel File Or Fomat", "Error rbi", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); conn.Dispose(); } return(list); }
public void Register(String Username, int Gid, String Password) { //checking pass length if (Password.Length < 4 || Password.Length > 16) { throw new InvalidOperationException("Password length should be in range of 4-16"); } //checking if only latters and numbers bool valid = Password.All(c => char.IsLetterOrDigit(c)); if (!valid) { throw new InvalidOperationException("A valid password should contain only letters and numbers"); } User tmpUser = new User(Gid, Username, Hash.GetHashString(Password + "1337")); //creating tmp user if (userHandler.isUserExists(tmpUser)) // checking if this user is already exists { if (log != null) { this.log.Warn("attempt to register with the Username:"******", G-ID: " + Gid + ".a user with this Username and G-ID already exists"); } throw new InvalidOperationException("Username and GroupId already taken"); } else { userHandler.addUser(tmpUser); // adding user to database if (log != null) { log.Info("User registered successfully. Username: "******"group id: " + Gid); } } }
public List <String> getListUnitCode(String path) { List <String> list = new List <string>(); OleDbConnection conn = getConnect(path); try { conn.Open(); String cmd = "select * from [Totals$]"; OleDbCommand command = new OleDbCommand(cmd, conn); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { String data = reader[0].ToString(); if ((data != "") && (data.All(char.IsDigit))) { list.Add(data); } } } catch { MessageBox.Show("Please Check Version Excel File Or Fomat", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); conn.Dispose(); } return(list); }
//Displays menu and options public static int Menu() { Console.WriteLine("\nMANAGER MENU\n"); int chc = 0; while (chc < 1 || chc > 6) { Console.WriteLine("\t(1) Add Movie"); Console.WriteLine("\t(2) Remove Movie"); Console.WriteLine("\t(3) Edit Movie"); Console.WriteLine("\t(4) Process batch transaction file"); Console.WriteLine("\t(5) Access report menu"); Console.WriteLine("\t(6) Return to main menu"); Console.WriteLine("\nEnter number to select option: "); String input = Console.ReadLine(); if (input.All(char.IsNumber)) { chc = int.Parse(input); if (chc < 1 || chc > 6) { Console.WriteLine("\tError: Enter value between 1 and 6"); } } else { Console.WriteLine("\tError: Enter only numeric values"); } } return(chc); }
// this method validate the gridview input public Boolean checkGridview(String drp, String rdb, String txBox) { int num = 0; Boolean flag = true; if (drp == "Select") { ScriptManager.RegisterStartupScript(this, GetType(), "showalert11", "alert('Please choose the book choice!');", true); flag = false; } if (rdb == "" || rdb == null) { ScriptManager.RegisterStartupScript(this, GetType(), "showalert12", "alert('Pick rent or buy for your book!');", true); flag = false; } if (txBox == "") { ScriptManager.RegisterStartupScript(this, GetType(), "showalert13", "alert('Please put the quantity of book you like!');", true); flag = false; } else if (!txBox.All(char.IsNumber)) { ScriptManager.RegisterStartupScript(this, GetType(), "showalert14", "alert('Please put a number for your quantity!');", true); flag = false; } return(flag); } // checkGridview
private void bookQueryInput_TextChanged(object sender, EventArgs e) { String text = ((TextBox)sender).Text; if (text == null || text.Length == 0) { this.bookModel = null; this.renderBookSet(); return; } this.bookModel = new Book(); if (text.All(char.IsDigit)) { try { this.bookModel.id = int.Parse(text); } catch (Exception) { } } this.bookModel.name = text; this.renderBookSet(); return; }
private void customerQueryInput_TextChanged(object sender, System.EventArgs e) { String text = ((TextBox)sender).Text; if (text == null || text.Length == 0) { this.model = null; this.renderCustomerSet(); return; } this.model = new Customer(); if (text.All(char.IsDigit)) { try { this.model.id = int.Parse(text); } catch (Exception) { } } this.model.fullname = text; this.renderCustomerSet(); return; }
public override bool IsValid(object value) { if (!String.IsNullOrEmpty(value.ToString())) { String nationalid = value.ToString(); Boolean isdigit = nationalid.All(char.IsDigit); if (isdigit) { if (nationalid.Length == 10) { int one = Int32.Parse(nationalid[0].ToString()) * 10; int two = Int32.Parse(nationalid[1].ToString()) * 9; int three = Int32.Parse(nationalid[2].ToString()) * 8; int four = Int32.Parse(nationalid[3].ToString()) * 7; int five = Int32.Parse(nationalid[4].ToString()) * 6; int six = Int32.Parse(nationalid[5].ToString()) * 5; int seven = Int32.Parse(nationalid[6].ToString()) * 4; int eight = Int32.Parse(nationalid[7].ToString()) * 3; int nine = Int32.Parse(nationalid[8].ToString()) * 2; int controlnum = Int32.Parse(nationalid[9].ToString()); int valuenum = (one + two + three + four + five + six + seven + eight + nine) % 11; if (valuenum < 2) { if (controlnum == valuenum) { return(true); } else { return(false); } } else if (valuenum >= 2) { if (controlnum == 11 - valuenum) { return(true); } else { return(false); } } } else { return(false); } } else { return(false); } } return(true); }
public void TestRegistrarUsuario() { String Nombre = "Fernando"; String Apellido = "Paz"; Int64 dpi = 2679783400101; String mail = "@fernandopazgmail.com"; String Pass = "******"; String cui = dpi.ToString(); int tamanoDPI = cui.Length; String Cuenta = "002"; int CuentaInt = Int32.Parse(Cuenta); double saldo = 250.25; bool resultCuenta; resultCuenta = Cuenta.All(Char.IsDigit); if (string.IsNullOrEmpty(Nombre)) { Assert.Fail(); } else { // Method intentionally left empty. } if (string.IsNullOrEmpty(Apellido)) { Assert.Fail(); } if (string.IsNullOrEmpty(mail)) { Assert.Fail(); } if (string.IsNullOrEmpty(Pass)) { Assert.Fail(); } if (tamanoDPI < 0 && tamanoDPI > 14) { Assert.Fail(); } if (!resultCuenta) { Assert.Fail(); } bool Esperado; Esperado = Practica3_4.Registrousuarios.CrearUsuario(Nombre, Apellido, dpi, CuentaInt, saldo, mail, Pass); if (Esperado) { Assert.Pass(); } }
public static Boolean IsNumeric(String value) { return value.All(Char.IsDigit); }