2.5 中文/英文/数字/邮件地址合法性判断
<script language="javascript">
<!--
function isenglish(name) //英文值检测
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charcodeat(i) > 128)
return false;
}
return true;
}
function ischinese(name) //中文值检测
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charcodeat(i) > 128)
return true;
}
return false;
}
function ismail(name) // e-mail值检测
{
if(! isenglish(name))
return false;
i = name.indexof(" at ");
j = name dot lastindexof(" at ");
if(i == -1)
return false;
if(i != j)
return false;
if(i == name dot length)
return false;
return true;
}
function isnumber(name) //数值检测
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charat(i) < "0" || name.charat(i) > "9")
return false;
}
return true;
}
function checkform()
{
if(! ismail(form.email.value)) {
alert("您的电子邮件不合法!");
form.email.focus();
return false;
}
if(! isenglish(form.name.value)) {
alert("英文名不合法!");
form.name.focus();
return false;
}
if(! ischinese(form.cnname.value)) {
alert("中文名不合法!");
form.cnname.focus();
return false;
}
if(! isnumber(form.publiczipcode.value)) {
alert("邮政编码不合法!");
form.publiczipcode.focus();
return false;
}
return true;
}
//-->
</script>
2.6 限定表单项不能输入的字符
<script language="javascript">
<!--
function contain(str,charset)// 字符串包含测试函数
{
var i;
for(i=0;i<charset.length;i++)
if(str.indexof(charset.charat(i))>=0)
return true;
return false;
}
function checkform()
{
if ((contain(document.form.name.value, "%\(\)><")) || (contain(document.form.message.value, "%\(\)><")))
{
alert("输入了非法字符");
document.form.name.focus();
return false;
}
return true;
}
//-->
</script>
1. 检查一段字符串是否全由数字组成
---------------------------------------
<script language="javascript"><!--
function checknum(str){return str.match(/\d/)==null}
alert(checknum("1232142141"))
alert(checknum("123214214a1"))
// --></script>
2. 怎么判断是否是字符
---------------------------------------
if (/[^\x00-\xff]/g.test(s)) alert("含有汉字");
else alert("全是字符");
3. 怎么判断是否含有汉字
---------------------------------------
if (escape(str).indexof("%u")!=-1) alert("含有汉字");
else alert("全是字符");
4. 邮箱格式验证
---------------------------------------
//函数名:chkemail
//功能介绍:检查是否为email address
//参数说明:要检查的字符串
//返回值:0:不是 1:是
function chkemail(a)
{ var i=a.length;
var temp = a.indexof('@');
var tempd = a.indexof('.');
if (temp > 1) {
if ((i-temp) > 3){
if ((i-tempd)>0){
return 1;
}
}
}
return 0;
}
2
您可能感兴趣的文章:
- vue init初始化项目后 npm run dev报错 10% building modules 1/1 modules 0 activeevents
- axios 处理 302 状态码的解决方法
- [Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/feature
- react-native 在新版Xcode(10+)中运行出现的问题: node_modules/react-native/third-party/glog-0.3.4 , C compiler cannot create executables
- 使用puppeteer爬取网站并抓出404无效链接
- 【angular2+typeScript+ng-zorro】Carousel 走马灯的左右方向控件实现
- Cannot read property 'tap' of undefined
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论