87,907
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function Show(){
var str = document.f.txt.value;
var re= /[^a-zA-Z\u4e00-\u9fa5]/;
if (re.test(str)){
alert("不能输入非法字符");
}
}
</script>
</head>
<body>
<form action=" " name="f">
<input type="text" name="txt" size="13">
<input type="button" value="Go" onclick="Show()">
</form>
</body>
</html>
function CheckInput(str){
var pattern = /[^a-z\u4e00-\u9fa5]/gi;
if (pattern.test(str)){
alert("非法字符");
}
}
<input type="text" align="center" name="sex" size="13" onchange="Javascript:CheckInput(this.value);">
function CheckInput(str){
var pattern = /^[\u4e00-\u9fa5a-z]+$/gi;
if (!pattern.test(str)){
alert("非法字符");
}
}
<input type="text" align="center" name="sex" size="13" onchange="Javascript:CheckInput(this.value);">