freeCodeCamp/curriculum/challenges/chinese-traditional/14-responsive-web-design-22/learn-html-forms-by-buildin.../60f83e7bfc09900959f41e20.md

1.7 KiB

id title challengeType dashedName
60f83e7bfc09900959f41e20 步驟 19 0 step-19

--description--

一些 type 屬性值含有內置表單驗證。 例如, type="email" 要求該值是一個有效的電子郵件地址。

給密碼 input 元素添加自定義驗證,新增 minlength 屬性設置其值爲 8。 這樣密碼少於 8 個字符的時候會阻止提交。

--hints--

密碼 input 元素應該添加 minlength 屬性。

assert.notEqual(document.querySelector('input[type="password"]')?.minLength, -1);

應該將 minlength 屬性設置爲 8

assert.equal(document.querySelector('input[type="password"]')?.minLength, 8);

--seed--

--seed-contents--

<!DOCTYPE html>
<html>
  <head>
    <title>Registration Form</title>
      <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <h1>Registration Form</h1>
    <p>Please fill out this form with the required information</p>
    <form action='https://register-demo.freecodecamp.org'>
--fcc-editable-region--
      <fieldset>
        <label>Enter Your First Name: <input type="text" required /></label>
        <label>Enter Your Last Name: <input type="text" required /></label>
        <label>Enter Your Email: <input type="email" required /></label>
        <label>Create a New Password: <input type="password" required /></label>
      </fieldset>
--fcc-editable-region--
      <fieldset></fieldset>
      <fieldset></fieldset>
      <input type="submit" value="Submit" />
    </form>
  </body>
</html>
body {
  width: 100%;
  height: 100vh;
  margin: 0;
  background-color: #1b1b32;
    color: #f5f6f7;
}

label {
    display: block;
    margin: 0.5rem 0;
}