Data validation

Cards (23)

  • A length check checks how long a string is, such as a password being at least 8 char
  • A type check checks what type the data is such as ensuring a number is an integer before using it in a mathematical function
  • The 'ord()' function in python returns the ASCII value of any char that is in ASCII
  • The 'chr()' function is used to return the char represented by the inputted ASCII value
  • The 'ord()' function can be used with a for statement and try except statement to ensure a string contains only ascii values
  • A regular expression is a special sequence of characters which can be used to check that user input is in the correct 'form' or 'pattern'.
  • In the context of regular expressions what do the following mean?
    ? 0 or 1
    * 0 <=
    + 1<=
    , with nothing after is this or more
    , with something after is interpreted as with the value before or the value after
  • To check for the letter 'A' what regular expression be written?
    [A]
  • To check for any capital what regular expression could be written?
    [A-Z]
  • To check the letter 'A' appears 3 times, what regular expression could be written?
    [A]{3}
  • To check the letter 'C' appears 3 or more times, what regular expression could be written?
    [C]{3,}
  • To check the letter 'B' appears 2 or 3 times, what regular expression could be written?
    [B]{3,2}
  • To check if regular expression a or regular expression B are fufilled what could be written?
    a|b
  • Existence validation is a method of data validation that checks if the input is present or not empty.
  • Format validation is a method of data validation that checks if the input matches a specific format or pattern.
  • Field validation is a method of data validation that checks if the input falls within a specified range or set of values.
  • Regular expression validation is a method of data validation that uses patterns to match and validate input data.
  • Password check if it matches is 8 chars or longer has atleast one capital and has 2 or more numbers:
    import repassword_fill = Falsewhile not password_fill:
    password = input('Please input password: ')     
    if re.search(r'[A-Z]+', password) and re.search(r'[0-9]{2,}', password) and len (password) >=8: 
    print('That password is valid')
    password_fill = True 
    else: 
    print('Invalid password. Please try again.')
  • The 'in' operator can be used to test whether a string appears as a substring inside another string. If the first string is found inside the second string then the result is true otherwise false.
  • (re.match(r'^[a-zA-Z]*$')) will only allow letters as an email address
  • Black box is where you can only see the user interface
  • WHite box is where you can interact with the code
  • White box testing is common inb software development