抽时间写了一个带有自动校验功能的Html5用户注册Demo。使用到Handlebars模板技术和手机验证码校验。
以下是效果截图:
1.页面代码:usersRegister.hbs
XML/HTML Code复制内容到剪贴板
- <!DOCTYPE html>
-
-
-
- <html lang="en">
-
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <title>用户注册</title>
- <!--[if lt IE 9]>
- <script src="/assets/scripts/html5shiv.js"></script>
- <![endif]-->
- <link href="/assets/styles/jquery.idealforms.min.css" rel="stylesheet" media="screen" />
- <style type="text/css">
- body {
- font: normal 15px/1.5 Arial, Helvetica, Free Sans, sans-serif;
- color: #222;
- overflow-y: scroll;
- padding: 60px 0 0 0;
- }
- .main {
- width: 560px;
- height: 480px;
- margin: -50px auto;
- }
- #my-form {
- width: 560px;
- height: 450px;
- margin: 0 auto;
- border: 1px solid #ccc;
- padding: 3em;
- border-radius: 3px;
- box-shadow: 0 0 2px rgba(0, 0, 0, .2);
- }
- </style>
- <script type="text/javascript" src="/assets/scripts/jquery-1.8.2.min.js"></script>
- <script type="text/javascript" src="/assets/scripts/jquery.idealforms.js"></script>
- </head>
- <body>
-
- <div class="main" >
- <div style="height:5px;text-align:center;font-size:25px"> 欢迎您注册!</div>
-
- <form id="my-form" class="myform">
- <div>
- <label>用户名:</label><input id="username" name="username" type="text" />
- </div>
- <div>
-
- <label>密码:</label><input id="pass" name="password" type="text" />
- </div>
- <div>
- <label>邮箱:</label><input id="email" name="email"
- data-ideal="required email" type="email" />
- </div>
- <div>
- <label>电话:</label><input id="telephone" type="text" name="phone" data-ideal="phone" />
- </div>
- <div>
- <label>供应商V码:</label><input id="vCode" type="text" name="vCode" data-ideal="vCode" />
- </div>
- <div>
- <label>真实姓名:</label><input id="trueName" type="text" name="trueName" data-ideal="trueName" />
- </div>
- <div>
- <label>手机验证码:</label><input id="telCode" type="text" name="telCode" data-ideal="telCode" />
- </div>
- <div style="margin-bottom:5px;">
- <button id="getTelCode" type="button" style="margin-left:160px; margin-right:auto;" >获取手机校验码</button>
- <hr style="margin-top:5px; margin-bottom:5px;" />
- </div>
- <!--<div>
- <label>性别:</label>
- <select id="sex" name="sex">
- <option value="男">男</option>
- <option value="女">女</option>
- </select>
- </div>
- <div>
- <label>昵称:</label><input id="nickName" type="text" name="nickName" data-ideal="nickName" />
- </div>
- <div>
- <label>年龄:</label><input id="age" type="text" name="age" data-ideal="age" />
- </div>-->
- <!-- <div>
- <label>地址:</label><input type="text" name="address" data-ideal="address" />
- </div>
- <div>
- <label>QQ:</label><input type="text" name="qq" data-ideal="qq" />
- </div>
- <div>
- <label>邮编:</label><input type="text" name="zip" data-ideal="zip" />
- </div>
- <div>
- <label>传真:</label><input type="text" name="fax" data-ideal="fax" />
- </div>
- <div>
- <label>身份证:</label><input type="text" name="creditID" data-ideal="creditID" />
- </div>
- <div>
- <label>出生日期:</label><input name="date" class="datepicker"
- data-ideal="date" type="text" placeholder="月/日/年" />
- </div>
- <div>
- <label>上传头像:</label><input id="file" name="file" multiple
- type="file" />
- </div>
- <div>
- <label>个人主页:</label><input name="website" data-ideal="url"
- type="text" />
- </div>
- <div>
- <label>备注:</label>
- <textarea id="comments" name="comments"></textarea>
- </div>
- -->
- <!-- <div id="languages">
- <label>语言:</label> <label><input type="checkbox"
- name="langs[]" value="English" />英文</label> <label><input
- type="checkbox" name="langs[]" value="Chinese" />中文</label> <label><input
- type="checkbox" name="langs[]" value="Spanish" />西班牙文</label> <label><input
- type="checkbox" name="langs[]" value="French" />法文</label>
- </div>
- <div>
- <label>精通几门:</label> <label><input type="radio"
- name="radio" checked />1</label> <label><input type="radio"
- name="radio" />2</label> <label><input type="radio" name="radio" />3</label>
- <label><input type="radio" name="radio" />4</label>
- </div>
- <div>
- <label>国籍:</label> <select id="states" name="states">
- <option value="default">– 选择国籍 –</option>
- <option value="AL">阿拉伯</option>
- <option value="AK">中国</option>
- <option value="AZ">美国</option>
- <option value="AR">法国</option>
- <option value="CA">英国</option>
- <option value="CO">德国</option>
- <option value="CT">西班牙</option>
- <option value="DE">俄罗斯</option>
- </select>
- </div> -->
- <div style="margin-top:10px; margin-left:100px;margin-right:100px;">
- <button type="button" id="submit" class="submit">提交</button>
- <button id="reset" type="button" >重置</button>
- </div>
- </form>
-
- </div>
- <script type="text/javascript">
- var options = {
- onFail : function() {
- alert($myform.getInvalid().length + ' invalid fields.')
- },
- inputs : {
- 'password' : {
- filters : 'required pass'
- },
- 'username' : {
- filters : 'required username'
- },
- 'email' : {
- filters : 'required email'
- },
- 'phone' : {
- filters : 'required phone'
- },
- 'trueName' : {
- filters : 'required'
- },
- 'vCode' : {
- filters : 'required'
- },
- 'telCode' : {
- filters : 'required'
- }
- /*
- 'age' : {
- filters : 'required digits',
- data : {
- min : 16,
- max : 70
- }
- },
- 'file' : {
- filters : 'extension',
- data : {
- extension : [ 'jpg' ]
-  
|
请发表评论