脚本验证手机号码及其它
一.手机验证
<SCRIPT language=JavaScript type=text/JavaScript>
<!--
function phone_check()
{ if (document.form1.phone.value=="")
{
alert("请输入手机号码");
form1.phone.focus();
return false;
}
return true;
}
function phone_num_check()
{ var i;
for (i = 0; i <document.form1.phone.value.length; i++)
{
var c =document.form1.phone.value.charAt(i);
if (((c<"0") || (c>"9")))
{
alert ('输入的号码应该是数字');
form1.phone.focus();
return false;
}
}
return true;
}
function phone_len_check()
{
if (document.form1.phone.value.length != 11)
{
alert('请输入11位手机号码!');
form1.phone.focus();
return false;
}
return true;
}
function phone_num139_check()
{
if ((document.form1.phone.value.substring(0,3)=="139" )||(document.form1.phone.value.substring(0,3)=="138")||(document.form1.phone.value.substring(0,3)=="137")||(document.form1.phone.value.substring(0,3)=="136")||(document.form1.phone.value.substring(0,3)=="135"))
{
return true;
}
alert('对不起,现在该业务只适用于移动的用户!');
form1.phone.focus();
return false;
}
function form1_valid()
{
if (phone_check()&&phone_len_check()&&phone_num_check()&&phone_num139_check())
{
return true;
}
return false;
}
-->
</SCRIPT>
<script>
function subInnew()
{
window.open('','new','height=300, width=250, top=95,left=10,toolbar=0,menubar=0,location=0,scrollbars=0,fullscreen=no, resizable=no,directories=0,status=no');
document.fm.submit();
}
</script>
二.检查一段字符串是否全由数字组成
<script language="javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>
三.判断汉字
function isChinese(para)
on error resume next
dim str
dim i
if isNUll(para) then
isChinese=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isChinese=false
exit function
end if
for i=1 to len(str)
c=asc(mid(str,i,1))
if c>=0 then
isChinese=false
exit function
end if
next
isChinese=true
if err.number<>0 then err.clear
end function
%>
如:
if not isChinese(request("name")) then
errmsg=errmsg+"
"+"<li>用户名应为汉字"
founderr=true
else
username=trim(request("name"))
end if
这样更简单
for(i=0;i<realname.length;i++){
char=realname.charCodeAt(i);
if(!(char>255)){
alert("真实姓名应为汉字!");
userform.realname.focus();
return false;
}
}
取中文字符串拼音首字母串的函数
<%
response.write "<link href=style.css rel=stylesheet>"
if request.form("content")="" then
response.write "<center><form method=post action=asd.asp><input name=content type=text>__<input type=submit></form>"
else
function getpychar(char)
tmp=65536+asc(char)
if(tmp>=45217 and tmp<=45252) then
getpychar= "A"
elseif(tmp>=45253 and tmp<=45760) then
getpychar= "B"
elseif(tmp>=45761 and tmp<=46317) then
getpychar= "C"
elseif(tmp>=46318 and tmp<=46825) then
getpychar= "D"
elseif(tmp>=46826 and tmp<=47009) then
getpychar= "E"
elseif(tmp>=47010 and tmp<=47296) then
getpychar= "F"
elseif(tmp>=47297 and tmp<=47613) then
getpychar= "G"
elseif(tmp>=47614 and tmp<=48118) then
getpychar= "H"
elseif(tmp>=48119 and tmp<=49061) then
getpychar= "J"
elseif(tmp>=49062 and tmp<=49323) then
getpychar= "K"
elseif(tmp>=49324 and tmp<=49895) then
getpychar= "L"
elseif(tmp>=49896 and tmp<=50370) then
getpychar= "M"
elseif(tmp>=50371 and tmp<=50613) then
getpychar= "N"
elseif(tmp>=50614 and tmp<=50621) then
getpychar= "O"
elseif(tmp>=50622 and tmp<=50905) then
getpychar= "P"
elseif(tmp>=50906 and tmp<=51386) then
getpychar= "Q"
elseif(tmp>=51387 and tmp<=51445) then
getpychar= "R"
elseif(tmp>=51446 and tmp<=52217) then
getpychar= "S"
elseif(tmp>=52218 and tmp<=52697) then
getpychar= "T"
elseif(tmp>=52698 and tmp<=52979) then
getpychar= "W"
elseif(tmp>=52980 and tmp<=53640) then
getpychar= "X"
elseif(tmp>=53689 and tmp<=54480) then
getpychar= "Y"
elseif(tmp>=54481 and tmp<=62289) then
getpychar= "Z"
else '如果不是中文,则不处理
getpychar=char
end if
end function
function getpy(str)
for i=1 to len(str)
getpy=getpy&getpychar(mid(str,i,1))
next
end function
content=request.form("content")
response.write "<center>"&getpy(content)&chr(10)
response.write "<br><br><br><a href=# οnclick=javascript:history.go(-1)>返回</a>"
end if
%>
四.只能输入数字的textbox
<input
οnkeypress="return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46"
οnpaste="return !clipboardData.getData('text').match(//D/)"
οndragenter="return false"
style="ime-mode:Disabled"
>
五.其它正则表达式
"^//d+$" 非负整数(正整数 + 0)
"^[0-9]*[1-9][0-9]*$" 正整数
"^((-//d+)|(0+))$" 非正整数(负整数 + 0)
"^-[0-9]*[1-9][0-9]*$" 负整数
"^-?//d+$" 整数
"^//d+(//.//d+)?$" 非负浮点数(正浮点数 + 0)
"^(([0-9]+//.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*//.[0-9]+)|([0-9]*[1-9][0-9]*))$" 正浮点数
"^((-//d+(//.//d+)?)|(0+(//.0+)?))$" 非正浮点数(负浮点数 + 0)
"^(-(([0-9]+//.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*//.[0-9]+)|([0-9]*[1-9][0-9]*)))$" 负浮点数
"^(-?//d+)(//.//d+)?$" 浮点数
"^[A-Za-z]+$" 由26个英文字母组成的字符串
"^[A-Z]+$" 由26个英文字母的大写组成的字符串
"^[a-z]+$" 由26个英文字母的小写组成的字符串
"^[A-Za-z0-9]+$" 由数字和26个英文字母组成的字符串
"^//w+$" 由数字、26个英文字母或者下划线组成的字符串
"^[//w-]+(//.[//w-]+)*@[//w-]+(//.[//w-]+)+$" email地址
"^[a-zA-z]+://(//w+(-//w+)*)(//.(//w+(-//w+)*))*(//?//S*)?$" url