JS-only Chinese and English characters can be entered
Use a regular expression object (RegExp) in js to judge
Chinese
^ [\ U0391-\ uFFE5] + $
English
^ [A-Za-z] + $
Chinese and English
/^ [\ U0391-\ uFFE5A-Za-z] + $/
Javascript Regular Expressions limit that only numbers, decimal places, English letters, Chinese characters, and other types of codes can be entered in a text box.
1. Only numeric code can be entered in the text box (decimal point cannot be entered)
<Input onkeyup = "this. value = this. value. replace (/\ D/g, '')" onafterpaste = "this. value = this. value. replace (/\ D/g, '')">
2. Only numbers can be entered, and decimal points can be entered.
<Input onkeyup = "if (isNaN (value) execCommand ('undo ')" onafterpaste = "if (isNaN (value) execCommand ('undo')">
<Input name = txt1 onchange = "if (/\ D /. test (this. value) {alert ('only numbers allowed '); this. value = '';}">
3. Number and decimal point method 2
<Input type = text tvalue = "" ovalue = "" onkeypress = "if (! This. value. match (/^ [\ + \-]? \ D *? \.? \ D *? $/) This. value = this. t_value; else this. tvalue = this. value; if (this. value. match (/^ (? : [\ + \-]? \ D + (? : \. \ D + )?)? $/) This. ovalue = this. value "onkeyup =" if (! This. value. match (/^ [\ + \-]? \ D *? \.? \ D *? $/) This. value = this. t_value; else this. tvalue = this. value; if (this. value. match (/^ (? : [\ + \-]? \ D + (? : \. \ D + )?)? $/) This. ovalue = 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. ovalue = this. value} ">
4. Only letters and Chinese characters can be entered
<Input onkeyup = "value = value. replace (/[\ d]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[\ d]/g, '')" maxlength = 10 name = "Numbers">
5. Only English letters and numbers are allowed. Chinese characters are not allowed.
<Input onkeyup = "value = value. replace (/[^ \ w \. \/]/ig,'') ">
6. Only numbers and English letters can be entered. <font color = "Red"> chun </font>
<Input onKeyUp = "value = value. replace (/[^ \ d | chun]/g,'') ">
7. After the decimal point, you can enter a maximum of two digits (numbers and Chinese characters). You cannot enter letters or operator numbers:
<Input onKeyPress = "if (event. keyCode <48 | event. keyCode> 57) & event. keyCode! = 46 |/\. \ d $/. test (value) event. returnValue = false ">
8. A maximum of two digits (numbers, letters, and Chinese characters) can be entered after the decimal point. You can enter the operator number:
<Input onkeyup = "this. value = this. value. replace (/^ (\-) * (\ d + )\. (\ d ). * $/, '$1 $2. $ 3') ">
----------------------------------------
Only Chinese characters can be entered:
<Input onkeyup = "value = value. replace (/[^ \ u4E00-\ u9FA5]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ u4E00-\ u9FA5]/g, '')">
Only numbers can be entered:
<Input onkeyup = "value = value. replace (/[^ \ d]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')">
Only English letters and numbers can be entered:
<Input onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')">
The control input box can only contain text, numbers, or special characters.
The following characters cannot be entered! @ # $ % ^ & *) <Br>
<Textarea rows = 2 cols = 20 name = comments onKeypress = "if (event. keyCode> 32 & event. keyCode <48) | (event. keyCode> 57 & event. keyCode <65) | (event. keyCode> 90 & event. keyCode <97) event. returnValue = false; ">
Enter spaces only
Onkeyup = "value = value. replace (/\ s/g ,'')"
Only Chinese and English characters can be entered:
Onkeyup = "value = value. replace (/[^ \ a-zA-Z \ u4E00-\ u9FA5]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ a-zA-Z \ u4E00-\ u9FA5]/g ,''))"