HTML JS 数据校验
2024-10-15 13:16:18
用到了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字段必须满足正则表达式
最新文章
- D1
- 快速升级php5.6
- JavaScript----函数的封装、继承和多态
- javascript获取选中的文本/html
- 常用排序算法的python实现和性能分析
- DIL中基本数据类型
- HTML基础知识(表格、表单)
- 94、存储库之MongoDB、mysql
- log4j常见的五个等级
- python3编码(encode,decode)
- Python关于Pyqt
- CGLIB 和 JDK生成动态代理类的区别(转)
- day08 服务
- 【PyQt5-Qt Designer】窗口操作
- SpringCloud 启动时报No active profile set, falling back to default profiles default
- 《Python计算机视觉编程》
- 使用zabbix发送邮件的简易设置流程(存档用)
- 如何使用Total Recorder录制网上的音乐,如何下载只能试听的歌曲
- python django-admin startproject django-admin命令未找到
- javaSE练习2——流程控制_2.1
热门文章
- CSUOJ Water Drinking
- activiti初学
- ArduinoYun教程之OpenWrt-Yun与CLI配置Arduino Yun
- BZOJ1170 : [Balkan2007]Cipher
- xcode 拷贝新的ios image 进去以后 出现 the divices is locked
- memcached对key和value的限制 memcached的key最大长度和Value最大长度
- 使用Axure RP原型设计实践04,了解全局变量
- dispatch_group_async 使用详解
- uifont 字体详解
- C#编程(小结)---------- 小总结