How to tell the text box in JavaScript can only output English letters, Chinese characters and numbers, cannot enter special characters!

Source: Internet
Author: User

Js-can only be entered in Chinese and English
2008-11-08 10:17
Using the regular Expression object (REGEXP) in JS to judge
Chinese
^[\u0391-\uffe5]+$
English
^[a-za-z]+$
Chinese and English
/^[\u0391-\uffe5a-za-z]+$/

JS Regular expression limit text box can only enter numbers, decimal points, English letters, Chinese characters and other types of code

1. Text box can only enter a numeric code (the decimal point can not be entered)
<input onkeyup= "This.value=this.value.replace (/\d/g, ')" onafterpaste= "This.value=this.value.replace (/\D/g, ' ) ">
2. Only the number can be entered and the decimal point will be lost.
<input onkeyup= "if (IsNaN (value)) ExecCommand (' Undo ')" Onafterpaste= "if (IsNaN (value)) ExecCommand (' Undo ')" >
<input name=txt1 onchange= "if (/\d/.test (this.value)) {alert (' Input number only '); this.value= ';}" >
3. Number and decimal method two
<input type=text tvalue= "" ovalue= "" onkeypress= "if (!this.value.match.? \d*?$/)) This.value=this.t_value;else this.tvalue=this.value;if (This.value.match (?: [/^ (?: \. \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+)?)? $/)) This.ovalue=this.value "onblur=" if (!this.value.match (?: [/^ (?: \). \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 kanji 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 can be entered, not Chinese
<input onkeyup= "Value=value.replace (/[^\w\.\/]/ig, ')" >
6. Only enter numbers and English <font color= "Red" >chun</font>
<input onkeyup= "Value=value.replace (/[^\d|chun]/g, ')" >
7. Only a maximum of two digits after the decimal point (numeric, Chinese can be entered), can not enter letters and operation symbols:
<input onkeypress= "if ((event.keycode<48 | | event.keycode>57) && event.keycode!=46 | |/\.\d\d$/.test ( Value)) Event.returnvalue=false ">
8. Only a maximum of two digits after the decimal point (numbers, letters, Chinese can be entered), you can enter the operation symbol:
<input onkeyup= "This.value=this.value.replace (/^ (\-) * (\d+) \. ( \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 and numbers can be entered:
<input onkeyup= "Value=value.replace (/[\w]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ')) ">
Control input Box can only enter text or numbers, or you can not allow special characters to be entered
The following characters are not allowed here: (like [email protected]#$%^&*, etc.) <br>
<textarea rows=2 cols=20 name=comments onkeypress= "if ((Event.keycode > && event.keycode < 48) | | (Event.keycode > && event.keycode < 65) | | (Event.keycode > && event.keycode < 97)) Event.returnvalue = false; " >
Only whitespace input is forbidden
Onkeyup= "Value=value.replace (/\s/g, ')"
Only Chinese and English 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, ')) "

How to tell the text box in JavaScript can only output English letters, Chinese characters and numbers, cannot enter special characters!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.