表单递交合法性检测-只允许填写字母
类别: JavaScript教程
<script language="JavaScript">
<!--
function CheckForm()
{
if (document.form.yourname.value == "" )
{
alert ("请输入姓名!");
return false;
}
var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for (i=0; i < document.form.yourname.value.length; i++)
{
var CheckChar = document.form.yourname.value.charAt(i);
CheckChar = CheckChar.toUpperCase();
if (Letters.indexOf(CheckChar) == -1)
{
alert ("请输入英文姓名!");
return false;
}
}
}
// -->
</Script>
<form action="" name="form" method="post" onSubmit="return CheckForm()">
<div align="center">
<input type="text" name="yourname">
<input type="submit" name="submit" value="submit">
</div>
</form>
<!--
function CheckForm()
{
if (document.form.yourname.value == "" )
{
alert ("请输入姓名!");
return false;
}
var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for (i=0; i < document.form.yourname.value.length; i++)
{
var CheckChar = document.form.yourname.value.charAt(i);
CheckChar = CheckChar.toUpperCase();
if (Letters.indexOf(CheckChar) == -1)
{
alert ("请输入英文姓名!");
return false;
}
}
}
// -->
</Script>
<form action="" name="form" method="post" onSubmit="return CheckForm()">
<div align="center">
<input type="text" name="yourname">
<input type="submit" name="submit" value="submit">
</div>
</form>
- 上一篇: 表单递交合法性检测-不允许指定字符
- 下一篇: 表单递交合法性检测-只接受数字
-= 资 源 教 程 =-
文 章 搜 索