Docsity

(Intermediate HTML & CSS) Form Validation Knowledge Assessment Guide 2024, Exams of Computer Security

Partial preview of the text

Download (Intermediate HTML & CSS) Form Validation Knowledge Assessment Guide 2024 and more Exams Computer Security in PDF only on Docsity!

INTERMEDIATE HTML & CSS

Form Validation

KNOWLEDGE ASSESSMENT GUIDE

  1. Which HTML attribute is used to specify that an input field must be filled out before submitting the form?
    • a) required
    • b) validate
    • c) mandatory
    • d) necessary
    • Answer: a) required
    • Rationale: The required attribute is used in HTML to ensure that an input field must be filled out before submitting the form.
  2. What type of input does the pattern attribute validate?
    • a) Numeric values
    • b) Text values
    • c) Regular expressions
    • d) Email addresses
    • Answer: c) Regular expressions
    • Rationale: The pattern attribute uses regular expressions to validate the input value.
  3. Which JavaScript method is used to check the validity of a form element?
  • d) text
  • Answer: d) text
  • Rationale: While text is a valid input type, it does not have built-in validation like email, url, and number.

Fill-in-the-Blank Questions

  1. The __________ attribute in HTML5 is used to specify a regular expression that the input element's value is checked against.
  • Answer: pattern
  • Rationale: The pattern attribute is used to define a regular expression for input validation.
  1. In JavaScript, the __________ event is commonly used to trigger form validation before submission.
  • Answer: submit
  • Rationale: The submit event is used to trigger validation and prevent form submission if validation fails.
  1. The __________ attribute in an input element specifies that the input field must be filled out before submitting the form.
  • Answer: required
  • Rationale: The required attribute ensures that the input field is not left empty.
  1. To validate an email address in HTML5, the input type should be set to __________.
    • Answer: email
    • Rationale: The email input type provides built-in validation for email addresses.
  2. The __________ attribute in a form element disables the browser's default validation.
    • Answer: novalidate
    • Rationale: The novalidate attribute prevents the browser from performing its default validation.

True/False Questions

  1. The minlength attribute specifies the minimum number of characters allowed in an input field.
    • Answer: True
    • Rationale: The minlength attribute sets the minimum number of characters required for an input field.
  2. The max attribute can be used with the number input type to set a maximum value.
    • Answer: True
    • Rationale: The max attribute defines the maximum value for an input field of type number.
  • c) link
  • d) pattern
  • Answer: a) url
  • Rationale: The url input type ensures that the field contains a valid URL.
  1. What does the maxlength attribute specify?
  • a) The maximum number of characters allowed in an input field
  • b) The maximum value for a numeric input
  • c) The maximum number of input fields in a form
  • d) The maximum number of forms on a page
  • Answer: a) The maximum number of characters allowed in an input field
  • Rationale: The maxlength attribute limits the number of characters that can be entered in an input field.
  1. Which JavaScript property would you use to get the validation message of an invalid form field?
  • a) validationMessage
  • b) invalidMessage
  • c) errorMessage
  • d) checkMessage
  • Answer: a) validationMessage
  • Rationale: The validationMessage property returns the message that will be displayed if the field is invalid.
  1. Which attribute is used to specify the legal number intervals for an input field of type number?
  • a) step
  • b) interval
  • c) range
  • d) min
  • Answer: a) step
  • Rationale: The step attribute defines the legal number intervals for an input field of type number.
  1. What does the autocomplete attribute do when added to a form or input element?
  • a) Enables automatic form submission
  • b) Provides suggestions based on previous entries
  • c) Validates the form automatically
  • d) Disables form validation
  • Answer: b) Provides suggestions based on previous entries
  • Rationale: The autocomplete attribute enables the browser to provide suggestions based on previous entries in the form or input field.

Correct Answer: False

Rationale: While client-side form validation provides immediate feedback to users, it should always be complemented with server-side validation to prevent malicious attacks and ensure data integrity. Multiple Choice: Which CSS pseudo-class is used to style an input field that is being interacted with by the user? A) :hover B) :active C) :focus D) :interact

Correct Answer: C) :focus

Rationale: The :focus pseudo-class in CSS is used to style an element that is currently focused or being interacted with, making it useful for indicating active form fields. Fill-in-the-Blank: The pattern attribute in HTML is used to define a _ that the input's value must match.

Correct Answer: regular expression

Rationale: The pattern attribute allows developers to specify a regular expression that the input value must match, enabling custom validation rules for form fields. True/False: The autocomplete attribute in HTML is used to control whether a browser should remember the input value.

Correct Answer: True

Rationale: The autocomplete attribute can be set to "on" or "off" to control whether a browser should remember and autofill the input value based on the user's previous entries. Multiple Choice: Which attribute is used to specify the range of valid values for an input field in HTML5? A) range B) minmax C) valuespan D) step

Correct Answer: A) range

C) error-color D) message-color

Correct Answer: A) color

Rationale: The color property in CSS can be applied to error messages to change their text color, making them more noticeable to users. Fill-in-the-Blank: The novalidate attribute in an HTML form is used to disable _ validation.

Correct Answer: browser

Rationale: By adding the novalidate attribute to a form element, developers can prevent the browser from performing its default validation checks, allowing for custom validation scripts. True/False: The minlength attribute in HTML is used to define the minimum number of characters required in an input field.

Correct Answer: True

Rationale: The minlength attribute specifies the minimum number of characters that must be entered into an input field, ensuring a certain level of data input by the user.

Multiple Choice: Which CSS property can be used to create animated effects when a user submits a form? A) animation B) transition C) transform D) submit-effect

Correct Answer: A) animation

Rationale: The animation property in CSS allows developers to create dynamic and engaging effects when a user interacts with a form, enhancing the user experience. Fill-in-the-Blank: The placeholder attribute in HTML is used to provide _ text in an input field.

Correct Answer: hint

Rationale: The placeholder attribute offers users a hint or example of the expected input in an input field, guiding them on what to enter. True/False: The step attribute in HTML is used to define the increment value for an input field with type="number".

Rationale: By setting the border-radius property in CSS, designers can give form elements rounded corners, enhancing the visual appeal of the form. True/False: The autofocus attribute in HTML automatically focuses on the specified form field when the page loads.

Correct Answer: True

Rationale: The autofocus attribute can be used to automatically bring focus to a specific form field when the page loads, improving user convenience and efficiency. Multiple Choice: Which HTML attribute is used to provide a brief description of the purpose of an input field? A) title B) description C) placeholder D) alt

Correct Answer: A) title

Rationale: The title attribute in HTML is used to provide a tooltip that offers a brief description of the input field's purpose, aiding users in understanding its function.

Fill-in-the-Blank: The CSS property text-align can be used to align text within form _.

Correct Answer: elements

Rationale: By utilizing the text-align property in CSS, designers can align text within form elements, ensuring a consistent and visually appealing layout.

  1. Multiple Choice: Which of the following is NOT a commonly used method for form validation in HTML? A) Using JavaScript B) Using CSS C) Using HTML attributes D) Using a server-side script

Answer: B) Using CSS

Rationale: CSS is primarily used for styling the appearance of HTML elements and is not used for form validation.

  1. Fill in the Blank: _________ is a concept in form validation that ensures the data entered by the user meets certain criteria.

Answer: Validation

Rationale: Validation is the process of checking the user's input to make sure it meets the required criteria.

Answer: True

Rationale: Client-side validation helps users correct their input errors before submitting the form.

  1. Multiple Choice: Which JavaScript method is commonly used to programmatically validate a form before submitting it? A) verify() B) validate() C) checkValidity() D) confirm()

Answer: C) checkValidity()

Rationale: The checkValidity() method is used to check if a form is valid before submission.

  1. Fill in the Blank: The HTML <________> element can be used to display an error message when form validation fails.

Answer: span

Rationale: A `` element can be used to dynamically show error messages to the user when form validation fails.

  1. True/False: Regular expressions are commonly used in form validation to specify complex patterns that input data must match.

Answer: True

Rationale: Regular expressions are powerful tools for defining specific patterns that input data must adhere to for validation.

  1. Multiple Choice: Which HTML input type can be used to enforce that the user enters a valid email address? A) text B) number C) email D) tel

Answer: C) email

Rationale: The email input type ensures that the user enters a valid email address.

  1. Fill in the Blank: The HTML attribute _________ can be used to specify the minimum value that can be accepted in a number input field.

Answer: min

Rationale: The min attribute sets the minimum value that is allowed for a number input field.

  1. True/False: Form validation should only be done on the client-side to improve user experience without the need for server-side validation.

Answer: False

Rationale: Client-side validation enhances user experience, but server-side validation is necessary for security and data integrity.

  1. Multiple Choice: Which HTML attribute can be used to specify a custom error message to be displayed when form validation fails?