---
title: "用JS的正则表达式如何判断输入框内为中文或者是英文数字"
author: "java_frog"
date: "2008-09-18T20:01:12Z"
tags: []
slug: "js"
draft: false
lastmod: "2008-09-18T20:01:12Z"
id: 243710
url: "https://java-frog.iteye.com/blog/243710"
---

只能输入数字和英文的：
<input onkeyup="value=value.replace(//g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(//g,''))">
2.只能输入数字的：
<input onkeyup="value=value.replace(//g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(//g,''))">
3.只能输入全角的：
<input onkeyup="value=value.replace(//g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(//g,''))">
4.只能输入汉字的：
<input onkeyup="value=value.replace(//g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(//g,''))">
 

5.也可以这样： 输入数字和.，否则弹出输入有误
<input type=text name= caolig value ="" onblur="if (!(/^+\.?\d*$/.test(this.value)) ){alert('您的输入有误'); this.value='';this.focus();}">