用到了html字符串校验,这里记录一下。

 <html>
<head>
<script type="text/javascript">
function on_click(){
var email = document.getElementById("input1").value.trim();
var telph = document.getElementById("input2").value.trim(); if(email == "" ||telph == ""){
alert("The email or telph is blank!!!");
return false;
} if (email.indexOf("@") == -1){
alert("an @ is not in an email !!!");
return false;
} var re = /^([0-9]{3}-)?[0-9]{3}-[0-9]{4}$/;
if (re.test(telph) == false){
alert("telph number is not match xxx-xxxx or xxx-xxx-xxxx")
return false;
} alert("ok, email:" + email + ", telephone:" + telph);
return true;
}
</script>
</head> <body>
email: <input id = "input1"> </input> <br> <!--必须有@-->
telph: <input id = "input2"> </input> <br> <!--必须满足xxx-xxxx or xxx-xxx-xxxx-->
<button type="button" onclick=on_click()>test</button>
</body>
</html>

如图:

校验两个字段均不能为空

校验email字段必须包含@

校验telph字段必须满足正则表达式

最新文章

  1. D1
  2. 快速升级php5.6
  3. JavaScript----函数的封装、继承和多态
  4. javascript获取选中的文本/html
  5. 常用排序算法的python实现和性能分析
  6. DIL中基本数据类型
  7. HTML基础知识(表格、表单)
  8. 94、存储库之MongoDB、mysql
  9. log4j常见的五个等级
  10. python3编码(encode,decode)
  11. Python关于Pyqt
  12. CGLIB 和 JDK生成动态代理类的区别(转)
  13. day08 服务
  14. 【PyQt5-Qt Designer】窗口操作
  15. SpringCloud 启动时报No active profile set, falling back to default profiles default
  16. 《Python计算机视觉编程》
  17. 使用zabbix发送邮件的简易设置流程(存档用)
  18. 如何使用Total Recorder录制网上的音乐,如何下载只能试听的歌曲
  19. python django-admin startproject django-admin命令未找到
  20. javaSE练习2——流程控制_2.1

热门文章

  1. CSUOJ Water Drinking
  2. activiti初学
  3. ArduinoYun教程之OpenWrt-Yun与CLI配置Arduino Yun
  4. BZOJ1170 : [Balkan2007]Cipher
  5. xcode 拷贝新的ios image 进去以后 出现 the divices is locked
  6. memcached对key和value的限制 memcached的key最大长度和Value最大长度
  7. 使用Axure RP原型设计实践04,了解全局变量
  8. dispatch_group_async 使用详解
  9. uifont 字体详解
  10. C#编程(小结)---------- 小总结