public static void checkIfNumber(String Value) { //this checks if the input can be parsed as an integer if (String.IsNullOrEmpty(Value.TrimEnd())) return; try { int.Parse(Value); } catch (Exception e) { InputException IE = new InputException("The value needs to be a number",Source); valList.AddException(IE); throw IE; } }
public static void checkName(String Value) { //this is to check if all the words in value starts with an uppercase letter, to properly give names try { if (String.IsNullOrEmpty(Value.TrimEnd())) return; Value = Value.TrimEnd(); String[] splitter = Value.Split(' '); ArrayList AL = new ArrayList(); AL.AddRange(splitter); for (int x = 0; x < AL.Count; x++) { String cur = ((String)AL[x]).Substring(0, 1); cur = cur.ToUpper(); if (!((String)AL[x]).StartsWith(cur)) { InputException IE = new InputException("Each word needs to start with an uppercase letter", Source); valList.AddException(IE); throw IE; } } } catch (InputException ie) { throw ie; } catch (Exception ex) { InputException IE = new InputException("There can only be one space between each word", Source); valList.AddException(IE); throw IE; } }
public void AddException(InputException exception) { RemoveSource(exception.getSource()); ExceptionStack.Push(exception); }
public static void checkUpper(String Value) { //this is to check if the first letter of the Value is uppercase if (String.IsNullOrEmpty(Value.TrimEnd())) return; String cur = Value.Substring(0, 1); cur = cur.ToUpper(); if (!(Value).StartsWith(cur)) { InputException IE = new InputException("The first word needs to start with an uppercase letter", Source); valList.AddException(IE); throw IE; } }
public static void checkIfLetters(String Value) { try { bool check = false; for (int charpos = 0; charpos < Value.Length; charpos++) { check = (Char.IsLetter(Value, charpos)); if (check == false) { InputException IE = new InputException("The value needs to be letters only", Source); valList.AddException(IE); throw IE; } } } catch (Exception e) { InputException IE = new InputException("The value needs to be letters only", Source); valList.AddException(IE); throw IE; } }
public static void checkTelephone(String Value) { //this is to check if the number conforms to normal telephone numbers if (String.IsNullOrEmpty(Value.TrimEnd())) return; try { int.Parse(Value); } catch (Exception e) { InputException IE = new InputException("The value needs to be a telephone number \n without any brackets", Source); valList.AddException(IE); throw IE; } if (Value.Trim().Length != 10) { InputException IE = new InputException("The value needs to be 10 digits long", Source); valList.AddException(IE); throw IE; } }
public static void checkEmailAddress(String Value) { //this is to check if the value is able to be an Email Address if (String.IsNullOrEmpty(Value.TrimEnd())) return; Boolean atSign = false; for (int x = 0; x < Value.Length; x++) { if (Value.Substring(x, 1).Equals("@")) atSign = true; } if (!atSign) { InputException IE = new InputException("The value must be a valid email address", Source); valList.AddException(IE); throw IE; } }
public static void checkAboveZero(String Value) { //this is to check if the value as a number is greater than zero if (String.IsNullOrEmpty(Value.TrimEnd())) return; int cur; try { cur = int.Parse(Value); } catch (Exception e) { InputException IE = new InputException("The value needs to be a number", Source); valList.AddException(IE); throw IE; } if (cur <= 0) { InputException IE = new InputException("The value needs to larger than 0", Source); valList.AddException(IE); throw IE; } }
public static void checkInputMaskNumberLN(String Value, String Mask) { if (String.IsNullOrEmpty(Value.TrimEnd())) return; //this is to check if the value Conforms to the formatting of the mask eg. **/**/**** if (Value.Length != Mask.Length) { InputException IE = new InputException("The value must be the same size \n and conform to " + Mask, Source); valList.AddException(IE); throw IE; } for (int x = 0; x < Value.Length; x++) { if (!Mask.Substring(x, 1).Equals("*")) { if (!Mask.Substring(x, 1).Equals(Value.Substring(x, 1))) { InputException IE = new InputException("The value must conform to " + Mask, Source); valList.AddException(IE); throw IE; } } else { checkIfNumber(Value.Substring(x, 1)); } } }
public static void checkInvalidChars(String Value) { //this is to check a list of invalid characters to see that they are not present in Value if (String.IsNullOrEmpty(Value.TrimEnd())) return; for (int x = 0; x < Value.Length; x++) for (int y = 0; y < InvalidChars.Count; y ++) if (Value.Substring(x, 1).Equals(InvalidChars[y])) { InputException IE = new InputException("The value cannot contain invalid character " + InvalidChars[y], Source); valList.AddException(IE); throw IE; } }
public static void checkIfDate(String Value) { //this is to check if the value can be represented as a date if (String.IsNullOrEmpty(Value.TrimEnd())) return; try { DateTime.Parse(Value); } catch (Exception e) { InputException IE = new InputException("The value cannot be represented as a date", Source); valList.AddException(IE); throw IE; } }
public static void checkNumbersEqual(String Lower, String Higher) { //this is to check if Lower is smaller or equal to than the Higher number if ((String.IsNullOrEmpty(Lower.TrimEnd())) || (String.IsNullOrEmpty(Higher.TrimEnd()))) return; int cur1, cur2; try { cur1 = int.Parse(Lower); cur2 = int.Parse(Higher); } catch (Exception e) { InputException IE = new InputException("The value needs to be a number", Source); valList.AddException(IE); throw IE; } if (cur1 > cur2) { InputException IE = new InputException("The lower value cannot be higher than the high value", Source); valList.AddException(IE); throw IE; } }
public static void checkEmpty(String Value) { //this is to check if the Value is not empty if (String.IsNullOrEmpty(Value.TrimEnd())) { InputException IE = new InputException("This cannot be empty", Source); valList.AddException(IE); throw IE; } }