js正则验证邮箱、手机号、年龄
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
input.err{border-color:red;}
input.suc{border-color:blue;}
</style>
<script>
window.onload=function(){
var reg={
email:/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
tel:/[-]\d{}/,
age:/[-]|[-]{}|/,
cName:/^[\u4e00-\u9fa5]{,}/
}
var oF=document.getElementById('F1');
var aInp=oF.children;
for(var i=;i<aInp.length;i++){
aInp[i].onfocus=function(){
this.className='';
this.onblur=function(){
if(reg[this.name]){
if(!reg[this.name].test(this.value)){
this.className='err';
}else{
this.className='suc';
}
}
};
};
}
function check(){
for(var i=;i<aInp.length;i++){
if(reg[aInp[i].name]){
if(!reg[aInp[i].name].test(aInp[i].value)){
return false;
}
}
}
return true;
}
oF.onsubmit=function(){
for(var i=;i<aInp.length;i++){
if(reg[aInp[i].name]){
if(!reg[aInp[i].name].test(aInp[i].value)){
aInp[i].className='err';
}
}
}
if(!check()){
return false;
}
};
};
</script>
</head>
<body>
<form action="http://www.baidu.com" id="F1">
email:<input type="text" name="email" id="email">
tel:<input type="text" name="tel" id="tel">
age:<input type="text" name="age" id="age">
cName:<input type="text" name="cName" id="cName">
<input type="submit" value="提交">
</form>
</body>
</html>
js正则验证邮箱、手机号、年龄的更多相关文章
- js正则验证邮箱格式
首先总结一下邮箱的格式,邮箱由@分隔,左侧为用户名,右侧为邮箱域名,用户名可以由字母.数字._.-以及.组成,但是必须是以字母或数字开头,邮箱的域名是由字母.数字.-和.组成的,但是必须以.加上字母的 ...
- JS正则验证邮箱的格式
一.相关的代码 1 function test() 2 { 3 var temp = document.getElementById("text ...
- JS正则验证邮箱的格式(转)
转载自:https://www.cnblogs.com/dyllove98/archive/2013/06/28/3161626.html 一.相关的代码 function test() { var ...
- 正则表达式控制Input输入内容 ,js正则验证方法大全
https://blog.csdn.net/xushichang/article/details/4041507 //输入姓名的正则校验 e.currentTarget.value = e.curre ...
- 手机号码js正则验证
手机号码js正则验证 var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; if (!myreg.test($(" ...
- js正则验证特殊字符
js正则验证特殊字符 方案一 var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im, regCn = /[·!#¥(--):: ...
- js&jquery验证邮箱和手机号是否正确范例
实现源码: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ...
- JavaScript正则验证邮箱
正则表达式/^正则$/.test() <html> <head> <title>JavaScript</title> <meta charset= ...
- JS正则验证数字格式2
之前的博文:JS验证正数字,正则的一种正数规则1,中isNaN可以判断内容是否为数字,但是这种判断出来的数字,有的不是数字的标准格式.那篇博文中尝试了下用正则验证,但是忘了一种情况,小数点后无数字,小 ...
随机推荐
- UI键盘通知
#import "ViewController.h" @interface ViewController () @property (nonatomic,strong) UITex ...
- 你真的了解UIScrollView吗?
一:首先查看一下关于UIScrollView的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIScrollView : UIView <NSCoding& ...
- 转换Excel表格到MarkDown:exceltk
源码和下载: 源码:https://github.com/fanfeilong/exceltk 下载:http://files.cnblogs.com/files/math/exceltk0.0.9. ...
- Helpful Tool
Remote Connectivity Analyzer(Online) https://testconnectivity.microsoft.com/ https://technet.microso ...
- 定义返回Block的函数
鉴于Block与函数的相似性,先从返回函数指针的函数入手 返回函数指针的函数 int fun1(int arg){ return arg + 1;}int fun2(int arg){ return ...
- nutz如何体现mvc思想的
如何理解web mvc框架?? 一.没有使用mvc框架之前我们都是自己根据mvc分层思想的理解去把它物理化,比如:根据包的命名,根据类的后缀名,根据文件夹的命名去定义分层. 因为每个人对mvc的理解不 ...
- 常用的JAVA集合讲解
java.util包中包含了一系列重要的集合类,而对于集合类,主要需要掌握的就是它的内部结构,以及遍历集合的迭代模式. 接口:Collection Collection是最基本的集合接口,一个Coll ...
- 【转】ETL增量抽取——通过时间戳方式实现
这个实验主要思想是在创建数据库表的时候, 通过增加一个额外的字段,也就是时间戳字段, 例如在同步表 tt1 和表 tt2 的时候, 通过检查那个表是最新更新的,那个表就作为新表,而另外的表最为旧表被新 ...
- 记一次MongoDB Map&Reduce入门操作
需求说明 用Map&Reduce计算几个班级中,每个班级10岁和20岁之间学生的数量: 需求分析 学生表的字段: db.students.insert({classid:1, age:14, ...
- 大数据挖掘: FPGrowth初识--进行商品关联规则挖掘
@(hadoop)[Spark, MLlib, 数据挖掘, 关联规则, 算法] [TOC] 〇.简介 经典的关联规则挖掘算法包括Apriori算法和FP-growth算法.Apriori算法多次扫描交 ...