---
title: "设置输入框只能输入数字和逗号"
author: "starting"
date: "2011-03-16T11:52:10Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2011-03-16T11:52:10Z"
id: 963988
url: "https://starting.iteye.com/blog/963988"
---

只能输入数字

 onkeyup="this.value=this.value.replace(/\[^0-9]/,'')"  
 onkeypress="this.value=this.value.replace(/\[^0-9]/,'')"

 

可以输入数字和逗号

onkeyup="this.value=this.value.replace(/\[^0-9\\,]/,'')"  
 onkeypress="this.value=this.value.replace(/\[^0-9\\,]/,'')"