最全 H5 form 表单 + 正则验证

本文展示了一个包含多种输入类型的HTML表单示例,包括电子邮件、文本、日期等,并使用CSS进行了美化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<style type="text/css">
label {
width: 80px;
padding: 0;
display: inline-block;
margin: 0;
height: 25px;
text-align:justify;
/*text-justify:distribute-all-lines;!*ie6-8*!*/
text-align-last:justify;/* ie9*/
-moz-text-align-last:justify;/*ff*/
-webkit-text-align-last:justify;/*chrome 20+*/
}
@media screen and (-webkit-min-device-pixel-ratio:0){/* chrome*/
.test1:after{
content:".";
display: inline-block;
width:100%;
overflow:hidden;
height:0;
}
}
</style>

<form>
<p>
<label for="email">电子邮箱:</label>
<input type="email" required autofocus name="email" id="email" placeholder="您的电子邮箱">
</p>
<p>
<label for="username-search">用户名:</label>
<input type="text" pattern="^[\u4e00-\u9fa5]*$" required name="username" placeholder="请输入用户名">
<input type="search" placeholder="用户名搜索" autosave="www.yujie.com" results="5" name="username-search" id="username-search">
</p>
<p>
<label>性别:</label>
<input type="radio" value checked name="docVLGender" required>男
<input type="radio" value name="docVLGender">女
</p>
<p>
<label for="username-search">生日:</label>
<input type="date" min="1980-01-01" max="2011-3-16" name="birthday" id="birthday" value="1982-10-10">
</p>
<p>
<label for="blog">博客地址:</label>
<input type="url" name="blog" placeholder="您的博客地址" id="blog">
</p>
<p>
<label for="mobile">手机:</label>
<input type="tel" name="mobile" pattern="^1[3458]{1}[0-9]{9}$" id="mobile" placeholder="您的手机号">
</p>
<p>
<label id="label-working-year" for="working-year">工作年限:</label>
<input type="range" min="1" step="1" max="20" name="slider" name="working-year" id="working-year" placeholder="您的工作年限" value="3">
</p>
<p>
<label for="age">年龄:</label>
<input type="number" name="age" id="age" value="20" autocomplete="off" placeholder="您的年龄">
</p>
<p>
<label for="avatar">头像:</label>
<input type="image" src="ms.jpg" mce_src="ms.jpg" name="avatar" id="avatar" placeholder="点击选择头像">
</p>
</form>

转载于:https://www.cnblogs.com/zhpblog/p/6841511.html

H5 Form表单注册是一个常见的网页交互设计,通常包括姓名、邮箱、密码等字段让用户填写信息。下面是一个简单的HTML5注册表单的基本例子: ```html <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>用户注册</title> </head> <body> <form id="registerForm" action="/api/register" method="post"> <label for="username">用户名:</label> <input type="text" id="username" name="username" required><br> <label for="email">邮箱:</label> <input type="email" id="email" name="email" pattern="[a-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" required><br> <label for="password">密码:</label> <input type="password" id="password" name="password" minlength="6" required><br> <input type="submit" value="注册"> </form> <script> // JavaScript可以添加一些验证或提交前处理功能 document.getElementById('registerForm').addEventListener('submit', function(event) { event.preventDefault(); // 阻止表单默认提交 if (validateForm()) { // 自定义的验证函数 this.submit(); } }); function validateForm() { // 这里可以添加更复杂的验证逻辑,如检查密码强度、确认密码是否一致等 // 示例:检查邮箱格式 var email = document.getElementById('email').value; if (!isValidEmail(email)) return false; return true; } // 示例:邮箱格式验证函数 function isValidEmail(email) { var regex = /^[\w\-\.\+\%]+@[\w\-]+\.\w{2,}$/; // 简单的正则表达式 return regex.test(email); } </script> </body> </html> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值