gpt4 book ai didi

node.js - 单击提交时无法检查空或空

转载 作者:搜寻专家 更新时间:2023-11-01 00:27:17 25 4
gpt4 key购买 nike


点击提交时无法检查是否为空

当按下空格键时,空值将被发送到数据库。

按钮可以将发送的数据提交给数据库

请帮忙。

  <form #Register="ngForm">
<div style="width: 500px">

<br/>
<h4>New Reegister</h4>
<br/>

<div class="form-group">
<dt><label for="name">Name</label></dt>
<input [(ngModel)]="name" name="name" type="text" class="form-control" placeholder="input your name" data-bv-notempty-message="The name is required" required>
</div>

<div class="form-group">
<dt><label for="lastname">LastName</label></dt>
<input [(ngModel)]="lastname" name="lastname" type="text" class="form-control" placeholder="input your lastname" data-bv-notempty-message="The lastname is required" required>

</div>

<div class="form-group">
<dt><label for="email2">E-mail</label></dt>
<input [(ngModel)]="email2" name="email2" type="text" class="form-control" placeholder="input your email" data-bv-notempty-message="email" required [pattern]="emailRegex" >
<div class= "p-2 text-danger"> <small>* Require Example : xxxxx@gmail.com</small> </div>
</div>

<div class="form-group">
<dt><label for="password2">Password</label></dt>
<input [(ngModel)]="password2" name="password2" type="password" class="form-control" placeholder="input your password" minlength="4" required>
<div class= "p-2 text-danger"> <small>* Enter atleast 4 characters</small> </div>
</div>
<!--
<div class="form-group">
<label for="password3">Password Confirm</label>
<input [(ngModel)]="password3" name="password3" type="password" class="form-control" placeholder="input your password" required>
</div>
-->

<div class="form-group">
<dt><label for="passwordhint">Password Hint</label></dt>
<input [(ngModel)]="passwordhint" name="passwordhint" type="password" class="form-control" placeholder="input your password" minlength="4" required>
<div class= "p-2 text-danger"> <small>* Enter atleast 4 characters</small> </div>
</div>

<button type="submit" type="reset" class="btn btn-danger" [disabled]="!Register.valid" (click)="Regis()">Save</button>


</div>
</form>


无法检查数据是否为空

当按下空格键时,空值将被发送到数据库。

按钮可以将发送的数据提交给数据库

请帮忙。

最佳答案

数据“”是有效数据,但它是空的,不是 null。您可以在将其保存到数据库之前通过 trim 函数进行检查。

例如:

let str = ' ';
console.log(str.length) // Length = 1
str = str.trim();
// Here str = '' and you can check length of it
console.log(str.length) // Length = 0

更多详情:trim

关于node.js - 单击提交时无法检查空或空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56783688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com