js屏蔽非法字符
来源:互联网 发布:淘宝店铺数据排行 编辑:程序博客网 时间:2024/05/01 07:06
<script>
//计算字符长度
function
checkStrLen(string){
var
str,Num = 0;
for
(
var
i=0;i<string.length;i++){
str = string.substring(i,i+1);
if
(str<=
"~"
){
//判断是否双字节
Num+=1;
}
else
{
Num+=3;
}
}
return
Num;
}
function
check_data(){
var
userformat=/^(\w|[\u4E00-\u9FA5])+$/
var
emailformat=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
var
nostr=
"51cto|51ct0|root|妈的|傻逼|王八|admin|管理|bbs|blog|group"
;
var
pattern =
new
RegExp(nostr,
"gi"
);
//username
if
(document.getElementById(
'username'
).value==
""
){
alert(
"用户名不能为空。"
);
document.getElementById(
'username'
).focus();
document.getElementById(
'checkname'
).value =
"0"
;
return
false
;
}
else
if
(checkStrLen(document.getElementById(
'username'
).value)>15 || checkStrLen(document.getElementById(
'username'
).value)<4){
alert(
"用户名请填写4-15个字符长度的中文/字母/数字,同时请勿使用特殊字符。"
);
document.getElementById(
'username'
).focus();
document.getElementById(
'checkname'
).value =
"0"
;
return
false
;
}
else
if
(!userformat.test(document.getElementById(
'username'
).value)){
alert(
"用户名不能使用特殊字符。"
);
document.getElementById(
'username'
).focus();
document.getElementById(
'checkname'
).value =
"0"
;
return
false
;
}
else
if
(pattern.test(document.getElementById(
'username'
).value)){
alert(
"用户名包含敏感字符或被系统屏蔽。"
);
document.getElementById(
'username'
).focus();
return
false
;
}
else
if
(document.getElementById(
'usernameexist'
).value==1){
alert(
"此用户名已经被注册,请更换。"
);
document.getElementById(
'username'
).focus();
return
false
;
}
else
{
document.getElementById(
'checkname'
).value =
"1"
;
}
}
</script>
<form name=
"reg"
action=
""
method=
"post"
id=
"reg"
onSubmit=
"return check_data()"
autocomplete=
"off"
>
<input type=
"hidden"
name=
"reback"
value=
"http://www.51cto.com"
>
<input type=
"hidden"
name=
"fromuid"
value=
""
>
<input type=
"hidden"
name=
"reg_logfrom"
value=
"http://www.51cto.com"
>
<input type=
"hidden"
name=
"checkname"
id=
"checkname"
value=
"0"
>
<input name=
"step"
type=
"hidden"
value=
"1"
>
<table width=
"620"
border=
"0"
align=
"center"
cellpadding=
"0"
cellspacing=
"0"
>
<tr>
<td height=
"18"
colspan=
"3"
> </td>
</tr>
<tr>
<td width=
"180"
align=
"right"
valign=
"bottom"
class
=
"font1"
>用户名: <span style=
" color:#FF0000"
>*</span> </td>
<td width=
"2"
rowspan=
"9"
class
=
"font2"
></td>
<td width=
"440"
class
=
"font2"
> <input name=
"username"
id=
"username"
type=
"text teat1_1"
class
=
"teat1"
size=
"15"
onChange=
"usercheck('check')"
onBlur=
"usercheck('check')"
value=
""
> </td>
</tr>
<tr>
<td align=
"right"
valign=
"bottom"
class
=
"font1"
> </td>
<td height=
"30"
valign=
"top"
class
=
"font2"
><span id=
"check"
>4-15个字符长度的中文/字母/数字,请勿使用特殊字符</span></td>
</tr>
</table>
<table width=
"620"
border=
"0"
align=
"center"
cellpadding=
"0"
cellspacing=
"0"
>
<tr>
<td colspan=
"2"
> </td>
</tr>
<tr>
<td height=
"1"
colspan=
"2"
bgcolor=
"#EBEBEB"
></td>
</tr>
<tr>
<td height=
"22"
colspan=
"2"
> </td>
</tr>
<tr>
<td colspan=
"2"
align=
"center"
><input type=
"submit"
value=
"提交"
> <input type=
"button"
value=
"重置"
onclick=
"javascript:document.all.reg.reset();"
/></td>
</tr>
<tr>
<td height=
"22"
colspan=
"2"
> </td>
</tr>
</table>
</form
0 0
- js屏蔽非法字符
- java屏蔽非法字符
- 屏蔽非法字符
- js验证非法字符
- 屏蔽非法字符就这么简单
- js表单验证非法字符
- js正则 判断非法字符
- html 文本框屏蔽非法字符,解决js的replace函数使光标跳到文本最后的问题
- js检查不能有非法字符
- js 判断是否包含非法字符
- js正则表达式判断非法字符
- 用js实现非法字符的检测
- js的正则表达式过滤非法字符
- 关于EditText屏蔽Emoji表情及屏蔽其它非法字符带来的光标不准确问题
- JS检测输入字符是否包含非法字符
- js屏蔽某些特殊字符(IE下)
- JS 屏蔽非数字字符的输入
- 验证是否输入非法字符的js正则操作
- java屏蔽非法字符
- hdu2852——KiKi's K-Number
- xampp+apache+php:局域网中访问网站配置过程
- Cocos2d-x 游戏中插入广告(横幅)
- CVS和SVN的区别
- js屏蔽非法字符
- ASP.NET MVC分页实现
- 使用Bootstrap框架时,PC端测试小屏效果正常,移动端失效
- mybatis逆向工程生成xml映射文件
- Shell 函数 和 Shell echo命令 和 test命令
- poj3352--E - Road Construction(无向图加边成双连通)
- PHP首期基础班郊游记:独乐乐不如众乐乐
- 【黑马程序员】黑马入学准备篇:IO输入与输出 【下】
- 使用ksoap2 调用 WebService(实例:调用天气预报服务)