JS 其他(二)
<%
'********************************************
'函数功能:正则表达式校验
'参数patrn:要校验的类型
' "User" - 用户名
' "Truename" - 英文姓名
' "Passwd" - 密码
' "Tel" - 电话/传真
' "Mobil" - 手机
' "Date" - 日期(格式:yyyy-mm-dd)
' "Email" - 电子邮件
' "Postalcode" - 邮政编码
' "Search" - 搜索关键字
' "Int" - 整数
'参数strng:要校验的字串
'返回值:校验结果,正确返回true,错误返回false
'********************************************
Function IsVerify(patrn,strng)
strng=Trim(strng)
Select Case patrn
Case "User" '用户名
patrn="^[a-z]{1}([a-z0-9]|[._]){2,19}$"
Case "Truename" '英文姓名
patrn="^[a-zA-Z]{1,30}$"
Case "Passwd" '密码
patrn="^(\w){6,20}$"
Case "Tel" '电话/传真
patrn="^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$"
Case "Mobil" '手机
patrn="^(\d)+[-]?(\d){6,12}$"
Case "Date" '日期(格式:yyyy-mm-dd)
patrn="^[12]{1}(\d){3}[-][01]?(\d){1}[-][0123]?(\d){1}$"
Case "Email" '电子邮件
patrn="^((\w)|[-]|[.])+@(((\w)|[-])+[.])+[a-z]{2,4}$"
Case "Postalcode" '邮政编码
patrn="^[a-z0-9 ]{3,12}$"
Case "Search" '搜索关键字
patrn="^[^`~!@#$%^&*()+=|\\\[\]\{\}:;\'\,.<>/?]{1}[^`~!@$%^&()+=|\\\[\]\{\}:;\'\,.<>?]{0,19}$"
Case "Int" '整数
patrn="^[1-9]{1}[0-9]{0,6}$"
Case "Array"
patrn="^[0-9]{1}([0-9]|[\,]){0,150}$"
End Select
Dim regEx
Dim Match
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Matches = regEx.test(strng)
IsVerify = Matches
Set regEx = Nothing
End Function
'********************************************
'函数功能:对输入框的特殊字串进行过滤保存
'参数strPass:过滤前的字符串
'返回值:过滤后的字符串
'********************************************
Function SQLencode(byVal strPass)
strPass = Replace(strPass, "&", "&")
strPass = Replace(strPass, "<", "<")
strPass = Replace(strPass, ">", ">")
strPass = Replace(strPass, """", """)
strPass = Replace(strPass, "'", "'")
strPass = Replace(strPass, " ", " ")
strPass = Replace(strPass,chr(13)&chr(10),"<br/>")
SQLencode = strPass
End Function
'********************************************
'函数功能:对SQLencode函数过滤后的字符串进行还原
'参数strPass:经过过滤后的字符串
'返回值:还原的过滤前的字符串
'********************************************
Function SQLdecode(byVal strPass)
If Not isNull(strPass) Then
strPass = Replace(strPass, "<", "<")
strPass = Replace(strPass, ">", ">")
strPass = Replace(strPass, ""","""" )
strPass = Replace(strPass, "'","'" )
strPass = Replace(strPass,"<br/>",chr(13)&chr(10))
End If
SQLdecode = strPass
End Function
'********************************************
'函数功能:生成随机密码(字符为数字与大小写字母集合)
'参数length:密码长度
'返回值:随机密码
'********************************************
Function random(length)
Dim n,str
rnds=""
Randomize
For i=1 To length
n=Int(75*Rnd+48)
If (n>57 and n<65) Or (n>90 and n<97) Then
i=i-1
Else
rnds=rnds&Chr(n)
End If
Next
random=rnds
End Function
'********************************************
'函数功能:对密码进行加密/解密(最大长度为15位)
'********************************************
Function Encrypt(preString)
Dim pwds,s
pwds=""
s=Left(preString,15)
For i=1 To Len(s)
seed=170-Asc(Mid(s,i,1))-i
pwds=pwds & Chr(seed)
Next
Encrypt=pwds
End Function
'********************************************
'函数功能:格式化当前时间字串
'参数:无
'返回值:返回当前时间的纯数字字符串方式的表示(例如:当前时间2001-10-3 2:34:6,返回字符串"20011003023406")
'********************************************
Function TheDate()
y=year(date())
m=month(date())
d=day(date())
h=Hour(time())
n=Minute(time())
s=Second(time())
If Len(m)=1 Then m="0"&m
If Len(d)=1 Then d="0"&d
If Len(h)=1 Then h="0"&h
If Len(n)=1 Then n="0"&n
If Len(s)=1 Then s="0"&s
thedate=y&m&d&h&n&s
End Function
'********************************************
'函数功能:返回字符串的长度
'参数:字符串
'返回值:字符串长度
'********************************************
Function strLen(str)
dim p_len
p_len=0
strlen=0
if trim(str)<>"" then
p_len=len(trim(str))
for xx=1 to p_len
if asc(mid(str,xx,1))<0 then
strlen=int(strlen) + 2
else
strlen=int(strlen) + 1
end if
next
end if
End Function
'********************************************
'函数功能:发送邮件通知
'参数:字符串
'返回值:成功/失败
'********************************************
Function SendMail(ToAddress, Subject, Body)
On Error Resume Next
Set objMail = Server.CreateObject("JMail.Message")
objMail.From = ADR_Email
objMail.FromName = "ADR管理中心"
objMail.Subject = Subject
objMail.AddRecipient ToAddress
objMail.Body = Body
If objMail.Send("") Then
SendMail = True
Else
SendMail = False
End If
If Err.Number<> 0 Then SendMail = False
Set objMail = Nothing
On Error Goto 0
End Function
%>
/*********************************************************************************
* FUNCTION: isBetween
* PARAMETERS: val AS any value
* lo AS Lower limit to check
* hi AS Higher limit to check
* CALLS: NOTHING
* RETURNS: TRUE if val is between lo and hi both inclusive, otherwise false.
**********************************************************************************/
function isBetween (val, lo, hi) {
if ((val < lo) || (val > hi)) { return(false); }
else { return(true); }
}
/*********************************************************************************
* FUNCTION: isDate checks a valid date
* PARAMETERS: theStr AS String
* CALLS: isBetween, isInt
* RETURNS: TRUE if theStr is a valid date otherwise false.
**********************************************************************************/
function isDate (theStr) {
var the1st = theStr.indexOf('-');
var the2nd = theStr.lastIndexOf('-');
if (the1st == the2nd) { return(false); }
else {
var y = theStr.substring(0,the1st);
var m = theStr.substring(the1st+1,the2nd);
var d = theStr.substring(the2nd+1,theStr.length);
var maxDays = 31;
if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
return(false); }
else if (y.length < 4) { return(false); }
else if (!isBetween (m, 1, 12)) { return(false); }
else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
else if (m==2) {
if (y % 4 > 0) maxDays = 28;
else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
else maxDays = 29;
}
if (isBetween(d, 1, maxDays) == false) { return(false); }
else { return(true); }
}
}
/********************************************************************************
* FUNCTION: Compare Date! Which is the latest!
* PARAMETERS: lessDate,moreDate AS String
* CALLS: isDate,isBetween
* RETURNS: TRUE if lessDate<moreDate
*********************************************************************************/
function isComdate (lessDate , moreDate)
{
if (!isDate(lessDate)) { return(false);}
if (!isDate(moreDate)) { return(false);}
var less1st = lessDate.indexOf('-');
var less2nd = lessDate.lastIndexOf('-');
var more1st = moreDate.indexOf('-');
var more2nd = moreDate.lastIndexOf('-');
var lessy = lessDate.substring(0,less1st);
var lessm = lessDate.substring(less1st+1,less2nd);
var lessd = lessDate.substring(less2nd+1,lessDate.length);
var morey = moreDate.substring(0,more1st);
var morem = moreDate.substring(more1st+1,more2nd);
var mored = moreDate.substring(more2nd+1,moreDate.length);
var Date1 = new Date(lessy,lessm,lessd);
var Date2 = new Date(morey,morem,mored);
if (Date1>Date2) { return(false);}
return(true);
}
/*********************************************************************************
* FUNCTION isEmpty checks if the parameter is empty or null
* PARAMETER str AS String
**********************************************************************************/
function isEmpty (str) {
if ((str==null)||(str.length==0)) return true;
else return(false);
}
/*********************************************************************************
* FUNCTION isAllEmpty checks if all the character is empty or null
* PARAMETER str AS String
**********************************************************************************/
function isAllEmpty (str)
{
if ((str==null)||(str.length==0)) return true;
else
{
for (var i=0; i<str.length; i++)
{
if (str.substring(i,i+1)!=" ") return false;
}
return true
}
}
/*********************************************************************************
* FUNCTION: isInt
* PARAMETER: theStr AS String
* RETURNS: TRUE if the passed parameter is an integer, otherwise FALSE
* CALLS: isDigit
**********************************************************************************/
function isInt (theStr) {
var flag = true;
if (isEmpty(theStr)) { flag=false; }
else
{ for (var i=0; i<theStr.length; i++) {
if (isDigit(theStr.substring(i,i+1)) == false) {
flag = false; break;
}
}
}
return(flag);
}
/*********************************************************************************
* FUNCTION: isReal
* PARAMETER: heStr AS String
decLen AS Integer (how many digits after period)
* RETURNS: TRUE if theStr is a float, otherwise FALSE
* CALLS: isInt
**********************************************************************************/
function isReal (theStr, decLen) {
var dot1st = theStr.indexOf('.');
var dot2nd = theStr.lastIndexOf('.');
var OK = true;
if (isEmpty(theStr)) return false;
if (dot1st == -1) {
if (!isInt(theStr)) return(false);
else return(true);
}
else if (dot1st != dot2nd) return (false);
else if (dot1st==0) return (false);
else {
var intPart = theStr.substring(0, dot1st);
var decPart = theStr.substring(dot2nd+1);
if (decPart.length > decLen) return(false);
else if (!isInt(intPart) || !isInt(decPart)) return (false);
else if (isEmpty(decPart)) return (false);
else return(true);
}
}
/*********************************************************************************
* FUNCTION: isEmail
* PARAMETER: String (Email Address)
* RETURNS: TRUE if the String is a valid Email address
* FALSE if the passed string is not a valid Email Address
* EMAIL FORMAT: AnyName@EmailServer e.g; webmaster@hotmail.com
* @ sign can appear only once in the email address.
*********************************************************************************/
function isEmail (theStr) {
var atIndex = theStr.indexOf('@');
var dotIndex = theStr.indexOf('.', atIndex);
var flag = true;
theSub = theStr.substring(0, dotIndex+1)
if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length))
{ return(false); }
else { return(true); }
}
/*********************************************************************************
* FUNCTION: newWindow
* PARAMETERS: doc -> Document to open in the new window
hite -> Height of the new window
wide -> Width of the new window
bars -> 1-Scroll bars = YES 0-Scroll Bars = NO
resize -> 1-Resizable = YES 0-Resizable = NO
* CALLS: NONE
* RETURNS: New window instance
**********************************************************************************/
function newWindow (doc, wide, hite, bars, resize) {
var opt="toolbar=0,location=0,directories=0,status=0,menubar=0,";
var l = Math.floor((screen.width-wide)/2);
var t = Math.floor((screen.height-hite)/2);
opt+=("scrollbars="+bars+",");
opt+=("resizable="+resize+",");
opt+=("width="+wide+",");
opt+=("height="+hite+",");
opt+=("top="+t+",");
opt+=("left="+l);
winHandle=window.open(doc,'',opt);
return;
}
//校验数字:0-9数字的组合
function isDigit(s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
//检验法人代码
function isCorporationCode(s){
var patrn=/^(\d){15}$/;
if (!patrn.exec(s)) return false
return true
}
//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
function isRegisterUserName(s)
{
var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9._]){4,19}$/;
if (!patrn.exec(s)) return false
return true
}
//校验用户姓名:只能输入1-30个以字母开头的字串
function isTrueName(s)
{
var patrn=/^[^`~!@#$%^&*()+-=|\\\[\]\{\}:;\'\,.<>/? 0-9]{2,19}$/;
if (!patrn.exec(s)) return false
return true
}
//校验密码:只能输入6-15个字母、数字
function isPasswd(s)
{
var patrn=/^[a-zA-Z0-9]{6,15}$/;
if (!patrn.exec(s)) return false
return true
}
//检验体重
function isAvoirdupois(s)
{
var patrn=/^[1-9]{1}[0-9]{0,2}$/;
var patrn2=/^[1-9]{1}$/;
var intPart=s.indexOf('.');
var decPart=s.lastIndexOf('.');
if (intPart==-1 && patrn.exec(s) && eval(s)>=2 && eval(s)<=200) return true
if (intPart!=decPart || intPart==0 || intPart+2!=s.length) return false
if (!patrn.exec(s.substring(0,intPart)) || !patrn2.exec(s.substring(decPart+1))) return false
if (eval(s)<2 || eval(s)>200) return false
return true
}
//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
function isTel(s)
{
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
//校验手机号码:必须以数字开头,除数字外,可含有“-”
function isMobile(s)
{
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
if (!patrn.exec(s)) return false
return true
}
//校验地区代码
function isAreaCode(s)
{
var patrn=/^(\d){6}$/;
if (!patrn.exec(s)) return false
return true
}
//校验邮政编码
function isPostalCode(s)
{
var patrn=/^[1-9]{1}(\d){5}$/;
if (!patrn.exec(s)) return false
return true
}
//校验搜索关键字
function isSearch(s)
{
var patrn=/^[^`~!@#$%^&*()+=|\\\[\]\{\}:;\'\,.<>/? ]{1}[^`~!@$%^&()+=|\\\[\]\{\}:;\'\,.<>?]{0,19}$/;
if (!patrn.exec(s)) return false
return true
}
//校验是否为ip地址
function isIP(s)
{
var patrn=/^[0-9.]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
//检验页码是否正确
function isPage(s)
{
var patrn=/^[1-9]{1}[0-9]{0,2}$/;
if (!patrn.exec(s)) return false
return true
}
//表单输入值错误提示
function vErr(o,s){
alert(s);
if (o) o.focus();
return false;
}
//判断单选
function chkRadio(o){
for (i=0;i<o.length;i++){
if (o[i].checked) return true;
}
return false;
}
//====================================表单类================================
// 文件上传过程中判断文件类型
/*
<input type=file onchange="alert(this.value.match(/^(.*)(\.)(.{1,8})$/)[3])">
*/
//表单的值不能为空
function isNull(elem){
//var pattern=/^\s+|\s+$/;
if(elem.replace(/(^\s+|\s$)/g, "")==""){
return false;
}else{
return true;
}
}
//不能超过imax字符
function imax(elem){
if(elem.length>imax){
return false;
}else{
return true;
}
}
//不能少于imix字符
function imix(elem){
if(elem.length<imix){
return false;
}else{
return true;
}
}
//输入为中文判断
function isChinese(elem){
var pattern=/[^\x00-\xff]/g;
if(pattern.test(elem)){
//包含中文
return false;
}else{
//不包含中文
return true;
}
}
/* *********************************************************************************************************************
<html>
<head>
<script language="javascript">
<!--
function isChinese(elem){
var pattern=/[^\x00-\xff]/g;
if(pattern.test(elem)){
//包含中文
return false;
}else{
//不包含中文
return true;
}
}
function isReady(){
if(isChinese(str.chinese.value)==false){
alert("不能输入中文");
str.chinese.focus();
return false;
}
return true;
}
-->
</script>
</head>
<body>
<form name="str" onSubmit="return isReady();">
<input type="text" name="chinese">
<input type="submit" value="中文">
</form>
</body>
</html>
**************************************************************************************************************************** */
// =============================时间类========================================
//短时间(形如: 13:04:06)
//更具弹性的正则表达式:/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/
function isShortTime(elem){
var pattern=/^([0-9]{1,2})(:)([0-9]{1,2})(:)([0-9]{1,2})$/;
var temp=elem.match(pattern);
if(temp==null)
return false;
if(temp[1]>24)
return false;
if(temp[3]>60)
return false;
if(temp[5]>60)
return false;
return true;
}
//短日期(形如: 2003-12-18)
//更具弹性的正则表达式:/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/
function isShortDate(elem){
var pattern=/^(\d{4})(-)(\d{2})(-)(\d{2})$/;
var temp=elem.match(pattern);
if(temp==null){
return false;
}
//
var d=new Date(temp[1]+"/"+temp[3]+"/"+temp[5]);
return d.getFullYear()==temp[1]&&
(d.getMonth()+1)==temp[3]&&
d.getDate()==temp[5];
}
//长时间,形如(2003-12-18 13:04:06)
//更具弹性的正则表达示/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/
function isTime(elem){
var pattern=/^(\d{4})(-)(\d{2})(-)(\d{2})(\s+)(\d{2})(:)(\d{2})(:)(\d{2})$/;
var temp=elem.match(pattern);
if(temp==null) return false;
//date(year,month,date, hour,minutes,seconds)
var d=new Date(temp[1],temp[3]-1,temp[5],temp[7],temp[9],temp[11]);
return d.getFullYear()==temp[1]&&
(d.getMonth()+1)==temp[3]&&
d.getDate()==temp[5]&&
d.getHours()==temp[7]&&
d.getMinutes()==temp[9]&&
d.getSeconds()==temp[11];
}
//只有年月 形如: 2003-12
function isDate(elem){
var pattern=/^([0-9]{4}|[0-9]{2})-([0-9]{1,2})$/;
var temp=elem.match(pattern);
if(temp==null) return false;
//Date(year,month)
var d=new Date(temp[1],temp[2]-1);
return d.getYear()==temp[1]&&(d.getMonth()+1)==temp[2];
}
//只有小时与分 形如: 04:47
//timePat=/^([1-9]|1[0-2]):[0-5]d$/;
function isTM(elem){
var pattern=/^(\d{1,2})(-|\/|:)(\d{1,2})$/;
var temp=elem.match(pattern);
if(temp==null) return false;
var hour=parseInt(temp[1]);
var mint=parseInt(temp[3]);
if(hour>24) return false;
if(hour<0) return false;
if(mint>60) return false;
if(mint<0) return false;
return true;
}
//判断leapYear (格式2003-12-18) (没有测试)
function isLeapYear(elem){
//选用上面的函数检验elem的有效性
if(isShortDate(elem)==false){
//输入的时间不格式不正确
return false;
}
var temp=elem.split("-");
var year=parseInt(temp[0]);
if((year%100)==0){
return (year%400)==0;
}else{
return (year%4)==0;
}
}
// *******************************************************结束时间类*******************************************
//======================================浏览器类=============================
//浏览器版本检测
//获取浏览器的名字Netscape或者Microsoft Internet Explorer
var browserName=navigator.appName;
//获取浏览器的版本信息
var browserVersion=parseInt(navigator.appVersion);
var browser;
if(browserName=="Netscape"&&browserVersion==5){
browser="nn6"; //netspace6
}
else if(browserName="Netscape"&&browserVersion==4){
browser="nn4"; //netspace4
}
else if(browserName="Microsoft Internet Explorer"&&
browserVersion==4&&navigator.appVersion.indexOf("MSIE 6.0")!=-1){
browser="ie6"; //IE 6.0
}
else if(browserName="Microsoft Internet Explorer"&&
browserVersion==4&&
navigator.appVersion.indexOf("MSIE 5.5")!=-1){
browser="ie55"; //IE5.5
}
else if(browserName="Microsoft Internet Explorer"&&
browserVersion==4&&
navigator.appVersion.indexOf("MSIE 5.0")!=-1){
browser="ie5"; //IE5.0
}
else if(browserName="Microsoft Internet Explorer"&&
browserVersion==4){
browser="ie4"; //IE4
}
/*
if(browser=="nn6"||browser=="ie6"||browser=="ie55"||browser="ie5"){
//不与高版本要求的代码
}else if(browser=="ie4"){
//不兼容nn4的代码
}else if(browser=="nn4"){
//不兼容ie4的代码
}
*/
/* *********************************end browser **************************** */
//判断操作平台是不是win98
function isWin98(){
if(navigator.appVersion.indexOf("98")!=-1){
return true;
}else{
//alert("你使用不是windows98操作系统");
return false;
}
}
//分辨率的检测
function redirectPage(){
//分辨率初始化
var size;
if(screen.width==640&&screen.height==480)
return size="640 x 480";
if(screen.width==800&&screen.height==600)
return size="800 x 600";
if(screen.width==1024&&screen.height==768)
return size="1024 x 768";
else
return size="640 x 480";
}
// /////////////////////////结束浏览器类///////////////////////////////////////
发一个将阿拉伯数字转换成中文大写的函数:
function Chinese(num) //将阿拉伯数字翻译成中文的大写数字
{
if(!/^\d*(\.\d*)?$/.test(num)){alert("Number is wrong!"); return "Number is wrong!";}
var AA = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
var BB = new Array("","拾","佰","仟","萬","億","点","");
var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
for(var i=a[0].length-1; i>=0; i--)
{
switch(k)
{
case 0 : re = BB[7] + re; break;
case 4 : if(!new RegExp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0]))
re = BB[4] + re; break;
case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
}
if(k%4 == 2 && a[0].charAt(i+2) != 0 && a[0].charAt(i+1) == 0) re = AA[0] + re;
if(a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k%4] + re; k++;
}
if(a.length>1) //加上小数部分(如果有小数部分)
{
re += BB[6];
for(var i=0; i<a[1].length; i++) re += AA[a[1].charAt(i)];
}
return re;
}
//=================================字符串类===============================
//禁止全角
function isQj(elem){
//[\u4E00-\u9FA5]汉字﹐[\uFE30-\uFFA0]全角字符
var pattern=/[\uFE30-\uFFA0]/gi;
if(pattern.test(elem)){
//不为汉字
//alert("不能用全角");
//elem="";
return false;
}else{
//输入正常
return true;
}
}
//含有非法字符~!@%^&*();'\"?><[]{}\\|,:/=+—“”‘
function havegg(elem){
var str = "~!@%^&*();'\"?><[]{}\\|,:/=+—“”‘";
for(i=0;i<elem.length;i++)
if (str.indexOf(elem.charAt(i)) !=-1){
return false;
}
return true;
}
//由a-z和A-Z组成的字符串
function isStr(elem){
var pattern=/^[a-zA-Z]+$/;
if(pattern.test(elem)){
return true;
}else{
return false;
}
}
//由字符串和数字字符串组成
function isStrAndInt(elem){
var patten=/^[a-zA-Z0-9]+$/;
if(pattern.test(elem)){
return true;
}else{
return false;
}
}
//判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
function isStrin(elem){
var pattern=/^(\b[a-zA-Z]|\b_)([a-zA-Z0-9]+(_|\.)?[a-zA-Z0-9]*)+$/;
if(pattern.test(elem)){
return true;
}else{
return false;
}
}
// ////////////////////////字符串完毕/////////////////////////////////////////
//============================数字类=========================================
//邮政编码
//要求:无地区规律,但都是6位数字,最大值为(西藏拉萨850000),最小值为(呼和浩特010000)
function isPost(elem){
var pattern=/^[0-9]{6}$/;
if(!pattern.test(elem)){
return false;
}else{
if(parseInt(elem)<10000||parseInt(elem)>850000){
return false;
}
return true;
}
}
//整数(可以带正负符号或者不带符号表正数)
function isInt(elem){
var pattern=/^(\-|+)?\d+$/;
if(!pattern.test(elem)){
return false;
}else{
return true;
}
}
//负数
function isNegative(elem){
var pattern=/^\b\-d+$/;
if(!pattern.test(elem)){
return false;
}else{
return true;
}
}
//数字字符
function isFigStr(elem){
var pattern=/^\d+$/;
if(!pattern.test(elem)){
return false;
}else{
return true;
}
}
//不大于imax,不小于imix的整数
function isScopeInt(elem){
var imax=80000;
var imix=100;
//判断elem是否为整数,向上参考
if(isInt(elem)==false){
//alert("elem不是整数");
return false;
}
if(parseInt(elem)>imax){
return false;
}
if(parseInt(elem)<imix){
return false;
}
return true;
}
// //////////////////////////////////数据类结束////////////////////////////////
自定以右键菜单。
<HTML><HEAD><TITLE>右键菜单的淡入淡出效果</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<SCRIPT language=JavaScript>
<!-- // RightClickMenu
var intDelay=10; //设置菜单显示速度,越大越慢
var intInterval=5; //每次更改的透明度
function showmenuie5(){
var rightedge=document.body.clientWidth-event.clientX
var bottomedge=document.body.clientHeight-event.clientY
if (rightedge<ie5menu.offsetWidth)
ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth
else
ie5menu.style.left=document.body.scrollLeft+event.clientX
if (bottomedge<ie5menu.offsetHeight)
ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight
else
ie5menu.style.top=document.body.scrollTop+event.clientY
ie5menu.style.visibility="visible"
//ie5menu.style.visibility=""
ie5menu.filters.alpha.opacity=0
GradientShow()
return false
}
function hidemenuie5(){
//ie5menu.style.visibility="hidden"
GradientClose()
}
function highlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
}
}
function lowlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="#000000"
}
}
function jumptoie5(){
if (event.srcElement.className=="menuitems"){
if (event.srcElement.url != ''){
if (event.srcElement.getAttribute("target")!=null)
window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
else
window.location=event.srcElement.url
}
}
}
function GradientShow() //实现淡入的函数
{
ie5menu.filters.alpha.opacity+=intInterval
if (ie5menu.filters.alpha.opacity<100) setTimeout("GradientShow()",intDelay)
}
function GradientClose() //实现淡出的函数
{
ie5menu.filters.alpha.opacity-=intInterval
if (ie5menu.filters.alpha.opacity>0) {
setTimeout("GradientClose()",intDelay)
}
else {
ie5menu.style.visibility="hidden"
}
}
function ChangeBG() //改变菜单项的背景颜色,这里的两种颜色值可以改为你需要的
{
oEl=event.srcElement
if (oEl.style.background!="navy") {
oEl.style.background="navy"
}
else {
oEl.style.background="#cccccc"
}
}
// -->
</SCRIPT>
<STYLE type=text/css>
.cMenu {
FILTER: alpha(opacity=0);BACKGROUND-COLOR: #D6D3CE;BORDER-BOTTOM: #666666 2px solid; BORDER-LEFT: #E4E4E4 2px solid; BORDER-RIGHT: #666666 2px solid; BORDER-TOP: #E4E4E4 2px solid; COLOR: #000000; CURSOR: default; FONT-SIZE: 9pt; color:#000000;FONT-WEIGHT: normal; LINE-HEIGHT: 20px; POSITION: absolute; VISIBILITY: hidden; WIDTH: 110px
}
.menuitems {
font-size:9pt;
MARGIN: 2px;
PADDING-BOTTOM: 0px;
PADDING-LEFT: 15px;
PADDING-RIGHT: 3px;
PADDING-TOP: 0px;
}
</STYLE>
<META content="Microsoft FrontPage 4.0" name=GENERATOR>
</HEAD>
<BODY>
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>
</OBJECT>
<RIGHTCLICK><!--[if IE]>
<DIV class=cMenu id=ie5menu onclick=jumptoie5() onmouseout=lowlightie5()
onmouseover=highlightie5()>
<DIV class=menuitems url="javascript:click_obj(0)">后退</DIV>
<DIV class=menuitems url="javascript:click_obj(1)">前进</DIV>
<DIV class=menuhr><hr style="width:100%"></DIV>
<DIV class=menuitems url="javascript:click_obj(2)">刷新</DIV>
<DIV class=menuitems url="javascript:click_obj(3)">加入收藏夹</DIV>
<DIV class=menuitems url="javascript:click_obj(4)">查看源文件</DIV>
<DIV class=menuhr><hr style="width:100%"></DIV>
<DIV class=menuitems url="javascript:click_obj(5)">属性</DIV>
</DIV>
<![endif]-->
<SCRIPT language=JavaScript>
<!--
function click_obj(id){
switch(id){
case 0:
history.back()
break
case 1:
history.forward()
break
case 2:
window.location.reload()
break
case 3:
window.external.AddFavorite(location.href, document.title)
break
case 4:
window.location = "view-source:" + window.location.href
break
case 5:
document.all.WebBrowser.ExecWB(10,1)
break
}
}
if (document.all&&window.print){
ie5menu.className="cMenu"
document.oncontextmenu=showmenuie5
document.body.onclick=hidemenuie5
}
//-->
</SCRIPT>
</RIGHTCLICK>
</BODY></HTML>
KeyCode常数用法
--------------------------------------------------------------------------------
可在代码中的任何地方用下列常数代替实际值:
常数 值 描述
vbKeyLButton 0x1 鼠标左键
vbKeyRButton 0x2 鼠标右键
vbKeyCancel 0x3 CANCEL 键
vbKeyMButton 0x4 鼠标中键
vbKeyBack 0x8 BACKSPACE 键
vbKeyTab 0x9 TAB 键
vbKeyClear 0xC CLEAR 键
vbKeyReturn 0xD ENTER 键
vbKeyShift 0x10 SHIFT 键
vbKeyControl 0x11 CTRL 键
vbKeyMenu 0x12 MENU 键
vbKeyPause 0x13 PAUSE 键
vbKeyCapital 0x14 CAPS LOCK 键
vbKeyEscape 0x1B ESC 键
vbKeySpace 0x20 SPACEBAR 键
vbKeyPageUp 0x21 PAGE UP 键
vbKeyPageDown 0x22 PAGE DOWN 键
vbKeyEnd 0x23 END 键
vbKeyHome 0x24 HOME 键
vbKeyLeft 0x25 LEFT ARROW 键
vbKeyUp 0x26 UP ARROW 键
vbKeyRight 0x27 RIGHT ARROW 键
vbKeyDown 0x28 DOWN ARROW 键
vbKeySelect 0x29 SELECT 键
vbKeyPrint 0x2A PRINT SCREEN 键
vbKeyExecute 0x2B EXECUTE 键
vbKeySnapshot 0x2C SNAPSHOT 键
vbKeyInsert 0x2D INSERT 键
vbKeyDelete 0x2E DELETE 键
vbKeyHelp 0x2F HELP 键
vbKeyNumlock 0x90 NUM LOCK 键
A 至 Z 键与 A 杴 Z 字母的 ASCII 码相同:
常数 值 描述
vbKeyA 65 A 键
vbKeyB 66 B 键
vbKeyC 67 C 键
vbKeyD 68 D 键
vbKeyE 69 E 键
vbKeyF 70 F 键
vbKeyG 71 G 键
vbKeyH 72 H 键
vbKeyI 73 I 键
vbKeyJ 74 J 键
vbKeyK 75 K 键
vbKeyL 76 L 键
vbKeyM 77 M 键
vbKeyN 78 N 键
vbKeyO 79 O 键
vbKeyP 80 P 键
vbKeyQ 81 Q 键
vbKeyR 82 R 键
vbKeyS 83 S 键
vbKeyT 84 T 键
vbKeyU 85 U 键
vbKeyV 86 V 键
vbKeyW 87 W 键
vbKeyX 88 X 键
vbKeyY 89 Y 键
vbKeyZ 90 Z 键
0 至 9 键与数字 0 杴 9 的 ASCII 码相同:
常数 值 描述
vbKey0 48 0 键
vbKey1 49 1 键
vbKey2 50 2 键
vbKey3 51 3 键
vbKey4 52 4 键
vbKey5 53 5 键
vbKey6 54 6 键
vbKey7 55 7 键
vbKey8 56 8 键
vbKey9 57 9 键
下列常数代表数字键盘上的键:
常数 值 描述
vbKeyNumpad0 0x60 0 键
vbKeyNumpad1 0x61 1 键
vbKeyNumpad2 0x62 2 键
vbKeyNumpad3 0x63 3 键
vbKeyNumpad4 0x64 4 键
vbKeyNumpad5 0x65 5 键
vbKeyNumpad6 0x66 6 键
vbKeyNumpad7 0x67 7 键
vbKeyNumpad8 0x68 8 键
vbKeyNumpad9 0x69 9 键
vbKeyMultiply 0x6A MULTIPLICATION SIGN (*) 键
vbKeyAdd 0x6B PLUS SIGN (+) 键
vbKeySeparator 0x6C ENTER 键
vbKeySubtract 0x6D MINUS SIGN (杴) 键
vbKeyDecimal 0x6E DECIMAL POINT (.) 键
vbKeyDivide 0x6F DIVISION SIGN (/) 键
下列常数代表功能键:
常数 值 描述
vbKeyF1 0x70 F1 键
vbKeyF2 0x71 F2 键
vbKeyF3 0x72 F3 键
vbKeyF4 0x73 F4 键
vbKeyF5 0x74 F5 键
vbKeyF6 0x75 F6 键
vbKeyF7 0x76 F7 键
vbKeyF8 0x77 F8 键
vbKeyF9 0x78 F9 键
vbKeyF10 0x79 F10 键
vbKeyF11 0x7A F11 键
vbKeyF12 0x7B F12 键
vbKeyF13 0x7C F13 键
vbKeyF14 0x7D F14 键
vbKeyF15 0x7E F15 键
vbKeyF16 0x7F F16 键
PS:http://topic.csdn.net/t/20031124/17/2489689.html