Text boxes allow only numbers to be entered. Net/javascript

Source: Internet
Author: User

<input type= "text" name= "test" onkeyup= "test1.value= (This.value=this.value.replace (/\d/g,"). Substring (0,6)). SUBSTRING (0,3) "> <br/>
<input name= "Test1" type= "text" >

Use up and down are different

Enter only numbers, letters, underscores

<input id= "Txtshopnumber" runat= "Server" class= "Input_text" maxlength= "8" onkeyup= "Value=value.replace (/[^ (\-) \w \.\/]/ig, ') '/>

Common regular expressions can only enter numbers: "^[0-9]*$"
Only n digits can be entered: "^\d{n}$"
You can only enter at least n digits: "^\d{n,}$"
Only m-n digits can be entered: "^\d{m,n}$"
Only numbers starting with 0 and non-0 can be entered: "^ (0|[ 1-9][0-9]*) $ "
You can only enter a positive real number with two decimal places: "^[0-9]+ (. [ 0-9]{2})? $ "
You can only enter a positive real number with 1-3 decimal places: "^[0-9]+ (. [ 0-9]{1,3})? $ "
You can only enter a non-zero positive integer: "^\+?" [1-9] [0-9]*$]
Only non-zero negative integers can be entered: "^\-[1-9][0-9]*$"
Only characters with a length of 3 can be entered: "^. {3}$ "
You can only enter a string consisting of 26 English letters: "^[a-za-z]+$"
You can only enter a string consisting of 26 uppercase English 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 a number and 26 English letters: "^[a-za-z0-9]+$"
You can only enter a string consisting of a number, 26 letters, or underscores: "^\w+$"
Verify user password: "^[a-za-z]\w{5,17}$" is in the correct format: start with a letter, the length is between 6-18,

Only characters, numbers, and underscores can be included.
Verify that it contains ^%& ',; =?$\ "characters:" [^%& ',; =?$\x22]+ "
Only Chinese characters can be entered: "^[\u4e00-\u9fa5],{0,}$"
Verify email Address: "^\w+[-+." \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$ "
Verify InternetURL: "^http://([\w-]+\.) +[\w-]+ (/[\w-./?%&=]*)? $ "
Verify the phone number: "^ (\ (\d{3,4}\) |\d{3,4}-)? \d{7,8}$"

The correct format is: "Xxxx-xxxxxxx", "xxxx-xxxxxxxx", "xxx-xxxxxxx",

"Xxx-xxxxxxxx", "XXXXXXX", "XXXXXXXX".
Verify the Social Security number (15-bit or 18-digit number): "^\d{15}|\d{}18$"
Validation 12 months of the year: "^ (0?[ 1-9]|1[0-2]) $ "correct format:" 01 "-" 09 "and" 1 "" 12 "
Verify one months of 31 days: "^ ((0?[ 1-9]) | ((1|2) [0-9]) |30|31) $ "

The correct format is: "01" "09" and "1" "31".


Limit text boxes with regular expressions you 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 t_value= "" o_value= "" onkeypress= "if (!this.value.match.? \d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match (?: [/^ (?: \. \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+)?)? $/)) This.o_value=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.o_value=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 ') ">

Text boxes allow only numbers to be entered. Net/javascript

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.