判断输入框中是否包含中文

阅读 51

2023-07-13

<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<script language="javascript">  
function funcChina(){ var obj = document.form1.txtName.value; 
if(/.*[\u4e00-\u9fa5]+.*$/.test(obj)) 
{ 
alert("含有中文!"); 
return false; 
} 
alert("没有中文!");
return true; 
} 
</script> 
<form name="form1">
<input type="text" name="txtName">
<input type="button" name="butTxt" value="开始判断" οnclick="funcChina()">
</form>
</body>
</html>

精彩评论(0)

0 0 举报