没有接触过正则表达式, 求一个简单正则表达式,

lavender975 2012-03-07 02:48:11
<form name="frmLogin">
<input type="text" name="username" id="ids"/>
<input type="submit" vlaue="提交"/>
</form>


当点击提交 input name="username" 只能输入小写字母 输入其他的则提示(只能输入小写字母)
...全文
100 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
orli 2012-03-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 zsx841021 的回复:]
function us()
{
var name =document.getElementById("a").value;
var pa=/[^a-z/;

if(pa.test(name))
{
alert('只能输入小写字母');
this.value='';
}
}
[/Quote]

button里放个onlick触发,或者在script中用bind("click",function us(){...})触发~
三石-gary 2012-03-07
  • 打赏
  • 举报
回复

function us()
{
var name =document.getElementById("a").value;
var pa=/[^a-z/;

if(pa.test(name))
{
alert('只能输入小写字母');
this.value='';
}
}
夜色镇歌 2012-03-07
  • 打赏
  • 举报
回复
三石-gary 2012-03-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lavender975 的回复:]
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv……
[/Quote]
你想怎样处罚 us()?
lavender975 2012-03-07
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<form action="user" method="post">

<input name="username" id="a" type="text" /><br />
<input name="password" type="text" /><br />

<input name="" type="button" value=""/>
</form>

<script type="text/javascript">
var name =document.getElementById("a").value;
var pa=/[^a-z/;
function us()
{

}
</script>
</body>
</html>
]

能在帮我下么 ? 这个怎么完成
三石-gary 2012-03-07
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>

</head>
<body>
<input name=txt1 onchange="if(/[^a-z]/.test(this.value)){alert('只能输入小写字母');this.value='';}">
</body>
</html>

三石-gary 2012-03-07
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>

</head>
<body>
<input name=txt1 onchange="if(/[^a-z]/.test(this.value)){alert('只能输入小写字母');this.value='';}">





</body>
</html>
lavender975 2012-03-07
  • 打赏
  • 举报
回复
能给一个能看出效果的html页面嘛?
三石-gary 2012-03-07
  • 打赏
  • 举报
回复
<input type="text" name="username" id="ids" onchange="if(/[^a-z]/.test(this.value)){alert('只能输入小写字母');this.value='';}"/>
加在你代码后面就行了
lavender975 2012-03-07
  • 打赏
  • 举报
回复
怎么调用? 我对正则表达式没有接触过
三石-gary 2012-03-07
  • 打赏
  • 举报
回复
<input name=txt1 onchange="if(/[^a-z]/.test(this.value)){alert('只能输入小写字母');this.value='';}">
三石-gary 2012-03-07
  • 打赏
  • 举报
回复
<input name=txt1 onchange="if(/[a-z]/.test(this.value)){alert('只能输入小写字母');this.value='';}">

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧