angularjs+ionic注册页面表单验证(手机号、确认密码、60s后重发验证码)
在已建立tabs和路由的注册页面html:
功能:
- 进行了手机号、密码格式验证,两次密码输入是否相同的判断,都正确且复选框勾选后才可点击注册,进入tabs.mypage页面。
- 未进行验证码真正发送、获取后台验证码数据与输入验证码进行对比。
使用:
- 4-- novalidate:禁止执行<form>表单原生校验,避免与自己设置的校验方法起冲突
- 7-- type="number":限定输入数字类型;required:限定不能为空;ng-minlength/ng-maxlength:限定输入字符最小、最大长度
- 11-- type="password":语义化,密码格式;ng-pattern="/[a-zA-Z0-9]/":用正则限定输入数字或字母
- 20-- ng-click="getTestCode()":绑定点击事件;ng-bind="description":控制按钮显示文字;ng-disabled="canClick":控制按钮可用性,避免短时间内多次请求
- 25-- ng-show="":根据条件显示提示文字;registerForm.number:name为registerForm的<form>表单中name为number的<input>输入框;$dirty:<input>输入框已与用户进行交互;$invalid:<input>输入框内容未通过自己设置的校验。
- 33-- ng-disabled="registerForm.$invalid":<form>表单都通过了校验,才可用
注意:不要在<label>标签里添加点击事件!!
<ion-view title="注册账号">
<ion-content class="text-center register-content">
<div class="card">
<form name="registerForm" novalidate>
<label class="item item-input">
<span class="input-label">手机号</span>
<input type="number" placeholder="请输入11位手机号" name="number" required ng-minlength="11" ng-maxlength="11" ng-model="user.number">
</label>
<label class="item item-input">
<span class="input-label">输入密码</span>
<input type="password" placeholder="6-30位数字或字母" name="password" required ng-pattern="/[a-zA-Z0-9]/" ng-maxlength="30" ng-minlength="6" ng-model="user.password">
</label>
<label class="item item-input">
<span class="input-label">确认密码</span>
<input type="password" placeholder="再次输入密码" name="password2" required ng-model="password2">
</label>
<div class="item item-input">
<span class="input-label col-25">验证码</span>
<input type="text" name="testcode" required ng-model="user.testcode">
<button class="button gettestcode col-40" ng-click="getTestCode()" ng-bind="description" ng-disabled="canClick">
</button>
</div>
</form>
</div>
<span class="usererr assertive" ng-show="registerForm.number.$dirty && registerForm.number.$invalid">手机号输入有误</span>
<span class="usererr assertive" ng-show="registerForm.password.$dirty && registerForm.password.$invalid">密码输入格式有误</span>
<span class="usererr assertive" ng-show="registerForm.password2.$dirty && user.password!=password2">两次密码输入不一致</span>
<label class="useragree">
<input type="checkbox" name="useragree" ng-checked="true">
<span> 同意<a href="javascript:;">发货么用户协议</a></span>
</label>
</ion-radio>
<button class="button btn-load" ui-sref="tabs.mypage" ng-disabled="registerForm.$invalid">注册</button>
<br><br>
</ion-content>
</ion-view>
在路由绑定的控制器js:
功能:点击触发获取验证码函数,在倒计时59s期间不可再次发送请求。
注意:记得在控制器中注入$interval
$scope.canClick=false;
$scope.description="获取验证码";
var second=59;
var timerHandler;
$scope.getTestCode=function(){ timerHandler=$interval(function(){
if(second<=0){
$interval.cancel(timerHandler);
second=59;
$scope.description="获取验证码";
$scope.canClick=false;
}else{
$scope.description=second+"s后重发";
second--;
$scope.canClick=true;
}
},1000)
};



angularjs+ionic注册页面表单验证(手机号、确认密码、60s后重发验证码)的更多相关文章
- js正则表达式注册页面表单验证
可以这样校验 <html> <head> <meta http-equiv="Content-Type" content="text/htm ...
- JavaScript学习——使用JS完成注册页面表单校验
1.步骤分析 第一步:确定事件(onsubmit)并为其绑定一个函数 第二步:书写这个函数(获取用户输入的数据<获取数据时需要在指定位置定义一个 id>) 第三步:对用户输入的数据进行判断 ...
- JS应用实例1:注册页面表单校验
这里是简单的前端校验,后边还会介绍后台的校验. 多重校验保证获取安全数据 步骤: 1.确定事件onsubmit,并绑定函数 2.编写函数,作用是获取输入数据 3.判断数据是否合法,合法则提交,否则表单 ...
- JQuery注册页面表单检验完善
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- JavaScript学习——完善注册页面表单校验
1.之前我们已经使用弹出框的方式实现了表单校验的功能,但是此种方式用户体验效果很差 我们希望做成把提示信息和校验结果放在输入栏的后面. 2.步骤分析 (此案例基于HTML&CSS——网站注册页 ...
- 【JavaScript】案例一:使用JS完成注册页面表单校验——事件(onsubmit&onfocus&onblur)
(一)初版:事件(onsubmit) 步骤分析: 第一步:确定事件(onsubmit)并为其绑定一个函数 第二步:书写这个函数(获取用户输入的数据<获取数据时需要在指定位置定义一个 id> ...
- 分享一篇最近新写的jquery注册页面表单校验的程序,仅供参考
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 淘宝网购物车jquery源码和网易新用户注册页面表单验证的练习
淘宝网购物车源码: <html lang="en"> <head> <meta charset="UTF-8"> <t ...
- 把JSON数据载入到页面表单的两种思路(对easyui自带方法进行改进)
#把JSON数据载入到页面表单的两种思路(对easyui自带方法进行改进) ##背景 项目中经常需要把JSON数据填充到页面表单,一开始我使用easyui自带的form load方法,觉得效率很低,经 ...
随机推荐
- Mysql 创建数据库后修改属性
添加表字段 alter table table1 add transactor varchar(10) not Null; alter table table1 add id int unsign ...
- linux Cron 执行Django 任务计划
用shell 脚本调用python 脚本如下 #!/bin/bash export FLAVOR=liveexport PYTHONPATH=$PYTHONPATH:/home/alex/Django ...
- 一 APPIUM基本理论知识
1.APPIUM介绍 Appium 是一个自动化测试开源工具,支持 iOS 平台和 Android 平台上的原生应用,web 应用和混合应用.所谓的“移动原生应用”是指那些用 iOS SDK 或者 A ...
- Dev的关于XtraGrid的使用2
接着说,GirdControl如何定位和查找指定列显示值的行(注意是列的实显示值,而不是关联数据源列值) 下面请看代码: using DevExpress.XtraGrid.Views.Base; u ...
- Angular - - angular.injector、angular.module
angular.injector 创建一个injector对象, 调用injector对象的方法可用于获取服务以及依赖注入. 格式:angular.injector(modules); modules ...
- hive CliDriver 源码分析
664行 CliDriver main启动 public static void main(String[] args) throws Exception { int ret = new CliDri ...
- Windows API 函数浏览
AbortDoc 终止一项打印作业 是 是 ...
- jQuery的$(window).load与、(document).ready和window.onload的关系
jQuery的$(window).load与.(document).ready和window.onload的关系 $(function() { console.log('document.ready ...
- [心得]传统IT转互联网面试经验分享
http://www.newsmth.net/bbstcon.php?board=Java&gid=374779 传统IT外企干了8年,两年前转互联网的,面的和被面的都不少.这几天项目空档期, ...
- 《深度探索C++对象模型》笔记——Data语意学
Data Member的绑定 inline member functin躯体之内的一个data member绑定操作会在整个class声明完成之后才发生. argument list中的名称还是会在它 ...