Summary of character types input in the js control text box, and js text box

Source: Internet
Author: User

Summary of character types input in the js control text box, and js text box

Only numbers can be entered in the JS control text box.

Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ 0-9]/g, '')" onpaste = "value = value. replace (/[^ 0-9]/g, '')" oncontextmenu = "value = value. replace (/[^ 0-9]/g, '')">

Javascript control text box can only enter numbers, decimal points

Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ 0-9 \.] /g, '')" onpaste = "value = value. replace (/[^ \ 0-9 \.] /g, '')" oncontextmenu = "value = value. replace (/[^ \ 0-9 \.] /g, '')">

Javascript control text box can only be entered in English

Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ a-\ z \ A-\ Z]/g, '')" onpaste = "value = value. replace (/[^ \ a-\ z \ A-\ Z]/g, '')" oncontextmenu = "value = value. replace (/[^ \ a-\ z \ A-\ Z]/g, '')">

Only English and numbers can be entered in the JS control text box.

Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9]/g, '')" onpaste = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9]/g, '')" oncontextmenu = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9]/g, '')">

The JS control text box can only enter Chinese Characters

Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ u4E00-\ u9FA5]/g, '')" onpaste = "value = value. replace (/[^ \ u4E00-\ u9FA5]/g, '')" oncontextmenu = "value = value. replace (/[^ \ u4E00-\ u9FA5]/g, '')">

The JS control text box can only contain Chinese characters, English letters, and numbers.

Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5]/g, '')" onpaste = "value = value. replace (/[^\ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5]/g, '')" oncontextmenu = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5]/g, '')">

The JS control text box can only contain Chinese characters, English letters, numbers, and spaces.

Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5 \]/g, '')" onpaste = "value = value. replace (/[^\ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5 \]/g, '')" oncontextmenu = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5 \]/g, '')">

The javascript control text box can only contain Chinese characters, English letters, numbers, and decimal places.

Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5 \.] /g, '')" onpaste = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5 \.] /g, '')" oncontextmenu = "value = value. replace (/[^ \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5 \.] /g, '')">

All in all:

First input in '<input>'

Onkeyup = "value = value. replace (/[^ \ X]/g ,'')"

Then replace X in (/[\ X]/g, '') with the code you want to enter,

Chinese u4E00-u9FA5, number 0-9, English a-z \ A-Z, other symbols @, point or other symbols.

You can also use \ To separate multiple.
For example: Chinese and English + numbers + @ symbol + dot symbol \ a-\ z \ A-\ Z0-9 \ u4E00-\ u9FA5 \@\.

If you do not want to right-click the menu in the text box or paste the copied information

In '<input>', enter onpaste = "return false" oncontextmenu = "return false ;"

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.