Search -6ren">
gpt4 book ai didi

html - 在没有 Javascript 的情况下只允许输入标签中的数字

转载 作者:太空狗 更新时间:2023-10-29 13:32:46 24 4
gpt4 key购买 nike

我是新手。我正在创建一个网页,要求用户提供他们的 ID。我希望它成为必填字段并且只允许数字。如果您引导我朝着正确的方向前进,我将不胜感激。这是我目前所拥有的。

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Search</title>
</head>
<body>
<div>
<table align="center">
<tr>
<td class="label">
Enter ID:
</td>
<td>
<input type="text" name="UserId" id="UserId" />
</td>
</tr>
</table>
</div>
</body>
</html>

最佳答案

尽管可能建议通过 JS 或在服务器上进行更重的验证,HTML5 does support this通过模式属性。

<input type= "text" name= "name" pattern= "[0-9]"  title= "Title"/>

关于html - 在没有 Javascript 的情况下只允许输入标签中的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12533508/

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