asp检测表单输入EMAIL合法性的函数
来源:asp之家 时间:2007-10-16 13:39:00
表单验证做网站程序多多少少都会碰到,其中emai地址的合法性验证也算是一个典型的例子,网页表单的验证我们一般是先在客户端使用javascript代码来处理,这样可以为减少服务器的负担,当然一些重要的表单项我们还应该在服务器端也加上验证。
下面是表单email地址的验证,使用javascript代码:
if (document.form1.email.value.charAt(0)=="." ||
document.form1.email.value.charAt(0)=="@"||
document.form1.email.value.indexOf('@', 0) == -1 ||
document.form1.email.value.indexOf('.', 0) == -1 ||
document.form1.email.value.lastIndexOf("@")==document.form1.email.value.length-1 ||
document.form1.email.value.lastIndexOf(".")==document.form1.email.value.length-1)
{
alert("Email地址格式不正确!");
document.form1.email.focus();
return false;
}
下面是asp(vbscript)服务器端验证的函数(呵呵,代码好像有点长):
function IsValidEmail(email)
dim names, name, i, c
’Check for valid syntax in an email address.
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), ".") <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, "..") > 0 then
IsValidEmail = false
end if
end function
标签:表单,email,函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL用户账户管理和权限管理深入讲解
2024-01-20 22:42:59
MySQL分类排名和分组TOP N实例详解
2024-01-24 11:23:16
![](https://img.aspxhome.com/file/2023/3/106603_0s.png)
python中的插入排序的简单用法
2023-09-30 07:57:51
![](https://img.aspxhome.com/file/2023/3/63193_0s.png)
ASP 中 DateDiff 函数详解
2007-09-19 12:00:00
Python selenium环境搭建实现过程解析
2023-10-06 06:18:48
![](https://img.aspxhome.com/file/2023/1/63271_0s.png)
MybatisPlus如何处理Mysql的json类型
2024-01-27 14:23:19
![](https://img.aspxhome.com/file/2023/1/70591_0s.png)
MySQL中or、in、union与索引优化详析
2024-01-18 08:21:55
python技能之数据导出excel的实例代码
2022-09-21 15:01:53
![](https://img.aspxhome.com/file/2023/5/124745_0s.png)
Python实现强制复制粘贴的示例详解
2021-03-30 23:58:43
![](https://img.aspxhome.com/file/2023/6/69036_0s.png)
Python 并行化执行详细解析
2021-09-23 22:20:52
![](https://img.aspxhome.com/file/2023/0/70680_0s.png)
python如何实现反向迭代
2023-05-17 17:37:55
Python处理JSON时的值报错及编码报错的两则解决实录
2023-11-10 07:12:07
基于Python中isfile函数和isdir函数使用详解
2023-05-10 00:46:50
基于Vue的侧边目录组件的实现
2024-05-22 10:44:34
![](https://img.aspxhome.com/file/2023/8/123208_0s.gif)
使用keras时input_shape的维度表示问题说明
2023-05-10 02:52:25
![](https://img.aspxhome.com/file/2023/3/92193_0s.jpg)
python 统计代码行数简单实例
2022-05-08 21:04:34
Python爬虫实现搭建代理ip池
2022-05-19 06:57:11
![](https://img.aspxhome.com/file/2023/8/105618_0s.png)
MySQL利用procedure analyse()函数优化表结构
2024-01-17 14:51:00
Django项目之Elasticsearch搜索引擎的实例
2022-02-26 17:30:28
tensorflow常用函数API介绍
2022-10-18 17:49:54
![](https://img.aspxhome.com/file/2023/4/72714_0s.png)