ASP表单验证方法总结
发布时间:2007-10-06 22:43:00
标签:表单,验证,asp
虽然说表单验证在客户端使用javascript来验证已经可以了,但是我们为了防止访客绕过客户端验证也为了数据安全最好还是在服务器端加上必要的验证,下面我们以实例来讲述asp表单验证方法。
1、验证输入的数字
假设一个文本框
<form name="form1" method="post" action="">
<input type="text" name="textfield">
</form>
要求用户必须输入数字
if not isnumeric(Request.Form("textfield")) then
response.write "重新填写"
end if
要求限制数字长度,如你要用户输入oicq号码
此例限制了用户的输入只有为4到10位数字才有效
if len(Request.Form("textfield"))>10 or len(Request.Form("textfield"))<4 then
response.write "重新填写"
end if
当然上面用Request.Form和Request是一样的,随便你怎么写了。
2、验证用户输入的邮件地址
引用一段通用检测函数来说明
由于检验程序较长,将其定义为一函数来调用
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
上面的这段函数大家应该都看的懂,当然你可以修改这段代码,使得即使用户输入XXX@CCC.DDD是错误的邮件地址,因为DDD不是一个有效域名。
引用的时候可以这样写
if IsValidEmail(trim(request("textfield")))=false then
response.write "重新填写"
end if
0
投稿
猜你喜欢
- 问题:点击“SQL Server Configuration Manager”却显示“无法连接到WMI 提供程序 请注意,你只能使用SQL
- 中文编码问题一直是Python程序设计中很头痛的问题,本文对此较为详细的进行了总结归纳。具体如下: 当字符串是:'\u4e
- 1、Python中self的含义self,英文单词意思很明显,表示自己,本身。此处有几种潜在含义:1.这里的自己,指的是,实例Instanc
- 前言之前说了怎么写机器码到内存,然后调用。现在说说怎么优化。用Python发送微信消息给好友第二次优化再看一遍c语言的代码void Send
- 1.数据采集和标记先采集数据,再对数据进行标记。其中采集数据要就有代表性,以确保最终训练出来模型的准确性。2.特征选择选择特征的直观方法:直
- 服务器:#server.py#!/usr/bin/env python#-*-coding:utf-8-*-import sysimport
- Python 提供了两个级别访问的网络服务。:低级别的网络服务支持基本的 Socket,它提供了标准的 BSD Sockets API,可以
- Python编程时,经常需要跳过第一行读取文件内容。简单的做法是为每行设置一个line_num,然后判断line_num是否为1,如果不等于
- 一·逻辑运算符优先级:not>and>or符号名称描述and逻辑与运算当and的两边同时满足条件时,结果为
- 1. 直接采用命令行模式更新1.1 搜索框搜索cmd,然后以管理员模式打开1.2 执行命令python -m pip install --u
- Python 界有条不成文的准则: 计算密集型任务适合多进程,IO 密集型任务适合多线程。本篇来作个比较。通常来说多线程相对于多进程有优势,
- 协程协程简单来说就是一个更加轻量级的线程,并且不由操作系统内核管理,完全由程序所控制(在用户态执行)。协程在子程序内部是可中断的,然后转而执
- 定义字典 dic = {'a':"hello",'b':"how",
- Vue baseurl配置最近的一个vue项目,没有config文件夹,配置baseurl废了很大劲,终于找到了方法,感天动地o(╥﹏╥)o
- 前言Python提供了多个内置模块用于操作日期时间,像 calendar,time,datetime。time模块提供的接口与C标准库 ti
- 本文实例为大家分享了python递归全排列的实现方法,供大家参考,具体内容如下排列:从n个元素中任取m个元素,并按照一定的顺序进行排列,称为
- 通过LogMiner实现Oracle数据同步迁移为了实现Oracle数据库之间的数据同步,网上的资料比较少的时候。最好用的Oracle数据库
- 多数情况下,mysql在刚刚安装时是不支持中文的,这是由于编码的问题我们可以通过修改配置文件,永久实现mysql对中文的识别首先我们要先将文
- 反转链表首先讨论特殊节点如果节点在首位,则反转之后,首位节点的next值为nil。func reverse(head *ListNode)
- 当然,每个人都可以编写CSS代码,甚至你现在已经让它为你的项目工作了。但是CSS还可以更好吗?开始用这5个Tips改进你的CSS吧!1.合理