لا يمكن أن يكون حكم JS سوى رقم ونقطة عشرية (مقتطفات من معلومات أخرى ، تم نشرها هنا فقط للاستخدام الشخصي والبحث في المستقبل)
1. يمكن إدخال الأرقام فقط في مربع النص (باستثناء النقاط العشرية)
<input onKeyup = "this.value = this.value.replace (// d/g ، '')" onafterpaste = "this.value = this.value.replace (// d/g ، '')">
2. يمكن إدخال الأرقام والنقاط العشرية فقط.
<input onKeyup = "if (isnan (value)) execcommand ('undo')" onafterpaste = "if (isnan (value)) execcommand ('undo')">
<name input = txt1 onChange = "if (// d/.test (this.value)) {ALERT ('فقط إدخال الأرقام') ؛ this.value = '' ؛}">
3. العدد والنقطة العشرية اثنين
<type type = text t_value = "" o_value = "" onkeypress = "if (! this.value.match (/^[/+/-]؟/d*؟/./d*؟ $/)) هذا .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 "onblur =" 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} ">
4. أدخل الرسائل والشخصيات الصينية فقط
<input onKeyup = "value = value.replace (/[/d]/g ، '')" onbeforepaste = "clipboarddata.setdata ('text' ، clipboarddata.getData ('text'). rep lace (/[/d [/d" ] /g ، '')) "maxLength = 10 name =" number ">
5. أدخل فقط الحروف والأرقام الإنجليزية ، وليس الصينية
<input onKeyup = "value = value.replace (/[^/w/.///201/ ig ، '')">
6. فقط إدخال الأرقام والإنجليزية <font color = "red"> chun </font>
<input onKeyup = "value = value.replace (/[^/d | chun]/g ، '')">
7. لا يمكن أن يكون هناك سوى رقمين بعد النقطة العشرية (يمكن إدخال الأرقام والصينية) ، ولا يمكن إدخال الرسائل ورموز المشغل:
<input onkeypress = "if ((event.keycode <48 || event.keycode> 57) && event.keycode! = 46 || //./d/d$/. ">
8. لا يمكن أن يكون هناك سوى رقمين بعد النقطة العشرية (الأرقام والحروف والصينية) ، ويمكن إدخال رموز المشغل:
<input onKeyup = "this.value = this.value.replace (/^(/-)*(/d+)/. (/d/d).*$/، '$ 1 $ 2. $ 3')">
فقط الأرقام والنقاط العشرية والإضافة والطرح والضرب
onkeypress = "return event.keycode> = 4 && event.keycode <= 57"