javascript input text box to limit the type of

2009-02-07  来源:本站原创  分类:Web  人气:343 

javascript input text box to limit the type of

The regular, we used to write some code to the function, Now I come to you as a reference:

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title> input box control </ title>

</ head>

<body>

<p> input box control </ p>

<p> (1): can only enter the number without a decimal point:

<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">

</ p>

<p> (2): can only enter a number containing a decimal point: </ p>

<p> [Method 1]

<input type = text t_value = "" o_value = "" onkeypress = "if (! this.value.match (/ ^ [\ + \ -]? \ d *? \.? \ d *?$/)) this . value = this.t_value; else this.t_value = this.value; if (this.value.match (/^(?:[ \ + \ -]? \ d + (?: \. \ d +)?)?$ /)) this.o_value = this.value "onkeyup =" if (! this.value.match (/ ^ [\ + \ -]? \ d *? \.? \ d *?$/)) this.value = this.t_value; else this.t_value = this.value; if (this.value.match (/^(?:[ \ + \ -]? \ d + (?: \. \ d +)?)?$/) ) this.o_value = this.value "" if (! this.value.match (/^(?:[ \ + \ -]? \ d + (?: \. \ d +)? | \. \ d *?) ?$/)) this.value = this.o_value; else (if (this.value.match (/ ^ \. \ d +$/)) this.value = 0 + this.value; if (this.value.match (/ ^ \ .$/)) this.value = 0; this.o_value = this.value }"></ p>

<p> [Method 2]

<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"> </ p>

<p> (3): can only enter letters and characters:

<input onkeyup = "value = value.replace (/ [\ d] / g ,'')" onbeforepaste =" clipboardData.setData ( 'text', clipboardData.getData ( 'text'). replace (/ [\ d] / g ,''))" name = "Numbers">

</ p>

<p> (4): can only enter letters and numbers and can not input Chinese characters

<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">

</ p>

<p> (5): can only enter numbers and English letters in the chen

<input onKeyUp="value=value.replace(/[^\d|chen]/g,'')">

</ p>

<p> (6): decimal can only have a maximum of two and can not enter letters, Chinese and operational symbol

<input onkeyup = "value = value.replace (/ [^ \ w \. \ /] / ig ,'')" onKeyPress =" if ((event.keyCode <48 | | event.keyCode> 57) & & event. keyCode! = 46 | | / \. \ d \ d $ /. test (value)) event.returnValue = false ">

</ p>

</ body>

</ html>

Such restrictions method is effective not very good. But in no other way could also be considered when

相关文章