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

1.9 KiB

id title challengeType dashedName
60f84ec41116b209c280ba91 步驟 20 0 step-20

--description--

type="password" 內可以使用 pattern 屬性來使用正則表達式來校驗密碼。

給密碼 input 元素添加 pattern 屬性,要求輸入匹配 [a-z0-5]{8,}

上面是一個正則表達式,匹配 8 個以上的小寫字母或數字 05。 可以刪掉 minlength 屬性,測試一下。

--hints--

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

assert.isNotEmpty(document.querySelector('input[type="password"]')?.pattern);

你應該將 pattern 屬性的值設置爲 [a-z0-5]{8,}

assert.equal(document.querySelector('input[type="password"]')?.pattern, '[a-z0-5]{8,}');

應該刪除密碼 input 元素的 minlength 屬性。

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

--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" minlength="8" 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;
}