首页 > 解决方案 > 发帖前检查

问题描述

我正在使用 express,这是我的 html 文件代码:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>title</title>
  </head>
  <body>
        <form action="/createaccount" method = "POST">
            <p>Username</p>
            <input name="username" type="text" value="username">
            <p>Password</p>
            <input name="password" type="password" value="password">
            <input type="submit">
  </body>
</html>

我想在发布之前检查是否没有输入

标签: formsexpressinputnull

解决方案


<input name="username" type="text" value="username" required>

在输入字段中添加必需

如果您想在服务器端进行验证,请使用 express-validator https://express-validator.github.io/docs/


推荐阅读