JavaScript control input allows only a variety of specified content to be entered _javascript tips

Source: Internet
Author: User

1. Only allow numbers to be entered

<input name= "username" type= "text" onkeyup=
"Value=this.value.replace (/\d+/g, ')" >

2, only allowed to enter English letters, numbers and underscores (the following two ways to achieve)

<input name= "username" type= "text"
style= "ime-mode:disabled" >
<input name= "username" type= "text"
onkeyup= "Value=value.replace (/[^\w\.\/]/ig, ')" >

3, only allowed to enter English letters, numbers and =@#

<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^\w=@#]|_/ig, ')" >

4, only allowed to enter Chinese characters

<input name= "username" type= "text" onkeyup=
"Value=value.replace (/[^\u4e00-\u9fa5]/g, ')" >

1. Only allow numbers to be entered

<input name= "username" type= "text" onkeyup=
"Value=this.value.replace (/\d+/g, ')" >

2, only allowed to enter English letters, numbers and underscores (the following two ways to achieve)

<input name= "username" type= "text"
style= "ime-mode:disabled" >
<input name= "username" type= "text"
onkeyup= "Value=value.replace (/[^\w\.\/]/ig, ')" >

3, only allowed to enter English letters, numbers and =@#

<input name= "username" type= "text" onkeyup=
"Value=value.replace (/[^\w=@#]|_/ig, ')" >

4, only allowed to enter Chinese characters

<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^\u4e00-\u9fa5]/g, ')" >

Only numbers can be entered: "^[0-9]*$".
Only n digits can be entered: "^\d{n}$".
You can enter at least n digits: "^\d{n,}$".

You can enter only the number of m~n digits:. "^\d{m,n}$"
Only numbers beginning with 0 and not 0 can be entered: ^ (0|[ 1-9][0-9]*) $ ".

You can only enter positive real numbers with two decimal digits: ^[0-9]+ (. [ 0-9]{2})? $ ".

You can only enter positive real numbers with 1~3 decimal places: ^[0-9]+ (. [ 0-9]{1,3})? $ ".
You can only enter a Non-zero positive integer: "^\+?" [1-9] [0-9]*$].

You can only enter a Non-zero negative integer: "^\-[1-9][]0-9" *$.
You can only enter characters with a length of 3: "^. {3}$ ".

You can only enter a string of 26 English letters: "^[a-za-z]+$".
You can only enter a string consisting of 26 uppercase letters: "^[a-z]+$".

You can only enter a string consisting of 26 lowercase English letters: "^[a-z]+$".
You can only enter a string consisting of numbers and 26 English letters: "^[a-za-z0-9]+$".

You can only enter a string of numbers, 26 English letters, or underscores: "^\w+$".

Verify user password: "^[a-za-z]\w{5,17}$" is the correct format: start with a letter, length between 6~18, can only contain characters, numbers, and underscores.

Verify that there are ^%& ',; =?$\ ' and other characters: "[^%& ',; =?$\x22]+".

Only Chinese characters can be entered: "^[\u4e00-\u9fa5]{0,}$"

You can only enter numbers and decimal points, anti-paste:

<input type= "" "Text" onkeyup= "Value=value.replace (/[^0-9.] /g, '), Dxfqlld (); "Onpaste=" Value=value.replace (/[^0-9.] /g, "oncontextmenu=" Value=value.replace (/[^0-9.) /g, ")"/>

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.