最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
JavaScript简单验证表单空值及邮箱格式的方法
时间:2017-02-09 编辑:简简单单 来源:一聚教程网
运行效果图如下:
具体代码如下:
代码如下 | 复制代码 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
(一)验证必填项是否有空值。
(二)验证Email格式是否正确。
//判断内容是否为空 functionvalidate_form(thisform){ with(thisform){ if(!validate_required(name,"Name must be filled out!")){ name.focus(); returnfalse } } } functionvalidate_required(field,alerttxt){ with(field){ if(value==null||value==""){ alert(alerttxt); returnfalse }else{ returntrue } } } //判断内容是否符合email的格式 functionis_email_form(thisform){ with(thisform){ if(!checkEmail(email,"Not a valid e-mail address!")){ email.focus(); returnfalse; } } } functioncheckEmail(field, alertText){ with(field){ apos = value.indexOf("@"); dotPos = value.indexOf("."); if(apos<1 || dotPos-apos<2){ alert(alertText); returnfalse; }else{ returntrue; } } }
|
相关文章
- HTML简单购物数量小程序代码展示 10-31
- html canvas实现弹幕功能 10-31
- HTML中空格表示的意义 10-31
- html area标签解读 10-31
- html使用表单标签实现注册页面代码展示 10-31
- 使用HTML截图并保存为本地图片的代码展示 10-31