Use the regular limit input box can only enter a number/English/Chinese and so on _ regular expressions

Source: Internet
Author: User

Common HTML Regular expressions

1. Only numbers and English can be entered:

Copy Code code as follows:

<input onkeyup= "Value=value.replace (/[/w]/g,") "
Onbeforepaste= "Clipboarddata.setdata" (' Text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ') "
Id= "Text1" name= "Text1" >

2. Only numbers can be entered:
Copy Code code as follows:

<input onkeyup= "Value=value.replace (/[^/d]/g,") "
Onbeforepaste= "Clipboarddata.setdata" (' Text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ') "
Id= "Text2" name= "Text2" >

3. Only the full angle can be entered:
Copy Code code as follows:

<input onkeyup= "Value=value.replace (/[^/uff00-/uffff]/g,") "
Onbeforepaste= "Clipboarddata.setdata" (' Text ', Clipboarddata.getdata (' text '). Replace (/[^/uff00-/uffff]/g, ') "
Id= "Text3" name= "Text3" >

4. Only Chinese characters are entered:
Copy Code code as follows:

<input onkeyup= "Value=value.replace (/[^/u4e00-/u9fa5]/g,") "
Onbeforepaste= "Clipboarddata.setdata" (' Text ', Clipboarddata.getdata (' text '). Replace (/[^/u4e00-/u9fa5]/g, ') "
Id= "Text4" name= "TEXT4" >

5. Email Address verification:
Copy Code code as follows:

var Regu =
"^ ([0-9a-za-z]+) | ([0-9a-za-z]+[_.0-9a-za-z-]*[0-9a-za-z]+)] @ ([a-za-z0-9-]+[.]) + ([a-za-z]{2}|net|net|com|com|gov|gov|mil|mil|org|org|edu|edu|int|int) $ "
var re = new RegExp (Regu);
if (S.search (re)!=-1) {
return true;
} else {
Window.alert ("Please enter a valid legal e-mail address!") ")
return false;
}

6. ID Card:
Copy Code code as follows:

"^//d{17} (//d|x) $"

7.17 Kinds of regular expressions
Copy Code code as follows:

"^//d+$"//non-negative Integer (positive integer + 0)
"^[0-9]*[1-9][0-9]*$"//Positive integer
"^ ((-//d+) | (0+)) $ "//non-positive integer (negative integer + 0)
"^-[0-9]*[1-9][0-9]*$"//Negative integer
"^-?//d+$"//Integer
"^//d+ (//.//d+)? $"//nonnegative floating-point number (positive float + 0)
"^ ([0-9]+//. [0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*//. [0-9]+) | ([0-9]*[1-9][0-9]*)] $ "//Positive floating-point number
"^ ((-//d+ (//.//d+)?) | (0+ (//.0+)) $ "//non-positive floating-point number (negative floating-point number + 0)
^ (-([0-9]+//. [0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*//. [0-9]+) | ([0-9]*[1-9][0-9]*))] $ "//negative floating-point number
"^ (-?//d+) (//.//d+)? $"//floating-point number
"^[a-za-z]+$"//A string of 26 English letters
"^[a-z]+$"//A string of 26 uppercase letters
"^[a-z]+$"///a string consisting of 26 lowercase letters
"^[a-za-z0-9]+$"//A string of numbers and 26 English letters
"^//w+$"//A string of numbers, 26 English letters, or underscores
"^[//w-]+ (//.[ w-]+) *@[//w-]+ (//.[ w-]+) +$ "//email address
"^[a-za-z]+://(//w+ (-//w+) *) (//.) ( w+ (-//w+) *)) * (//?//s*) $ "//url

=============================================
1. The dashed box when the Cancel button is pressed
Add attribute value in input hidefocus or hidefocus=true

2. Read-only text box contents
Add attribute value in input readonly

3. Prevent back-emptying of the text document (you can make the style content as a class reference)
<input Style=behavior:url (#default #savehistory); Type=text
Id=opersistinput>

The 4.ENTER key allows the cursor to move to the next input box
<input onkeydown= "if (event.keycode==13) event.keycode=9" >

5. Only for Chinese (with flashing)
Copy Code code as follows:

<input onkeyup= "value="/value.replace (/["-~]/g,") "
Onkeydown= "if (event.keycode==13) event.keycode=9" >

6. Only for numbers (with flashing)
Copy Code code as follows:

<input onkeyup= "value="/value.replace (/["^/d]/g,")
"Onbeforepaste=" clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ') ">

7. Only for numbers (no flashing)
Copy Code code as follows:

<input ime-mode:disabled "
Onkeydown= "If" (event.keycode==13) event.keycode=9 "onkeypress=" if
((event.keycode<48 | | event.keycode>57)) Event.returnvalue=false ">

8. Can only input English and digital (with flashing)
Copy Code code as follows:

<input onkeyup= "value="/value.replace (/[/w]/g, "')"
Onbeforepaste= "Clipboarddata.setdata" (' Text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ') ">

9. Shielding Input Method
Copy Code code as follows:

<input type= "text" name= "url" ime-mode:disabled "
Onkeydown= "if (event.keycode==13) event.keycode=9" >

10. Only digits, decimal points, minus (-) characters (no flashing) can be entered.
Copy Code code as follows:

<input onkeypress= "If" (event.keycode!=46 && event.keycode!=45 &&
(event.keycode<48 | | event.keycode>57)) Event.returnvalue=false ">


11. Can only enter two decimal places, three decimal places (with flashing)
Copy Code code as follows:

<input maxlength=9
Onkeyup= "if (Value.match (/^/d{3}$/)) value="/value.replace (Value,parseint (VALUE/10)) "
; value= "/value.replace (//./d*/./g, '.") "onkeypress=" if (event.keycode<48
|| event.keycode>57) && event.keycode!=46 && event.keycode!=45 | |
Value.match (/^/d{3}$/) | | ./d{3}$/.test (value))
{Event.returnvalue=false} "Id=text_kfxe name=text_kfxe>

12. Only digits and commas can be entered

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <TITLE> New Document ;/title> <meta name= "generator" content= "EditPlus" > <meta name= "Author" content= "" > <meta NAME= "Keyw Ords "Content=" "> <meta name=" Description "content=" "> </HEAD> <BODY> <input onkeyup= ' Check (th
	is) '/> </BODY> <script> function Check (obj) {var sreg =/^-+.*/g;
	var zero =/^0[1-9]+\.*\d*/g;
	var val = obj.value;
	var plus = ';		
		if (Sreg.test (val)) {val = Val.replace (/-+/g, ');		
	plus = '-';	
	} val = Val.replace (/\s+/g, ');
	if (/^\.+.*$/.test (val)) {val = '; } val = Val.replace (/[^\d\.]
	/,''); val = val.replace (/(^\d+\.{
	1}) (\d*). */g, ' $1$2 ');
	val = val.replace (/(^\d+\.\d{3}) \d*/g, ' $ ');		
	val = Val.replace (/^[0]* (0{1}) ([1-9]*) (. *)/g, ' $1$2$3 ');
	if (Zero.test (val)) {val = Val.replace (/0 ([1-9]+) (. *) $/, ' $1$2 ');
} obj.value = Plus+val;
 } </script> </HTML>

13, the replacement of the contents of the non-digital and Chinese and English characters

function Renumdou (str) {
var regexp =/[^\d,,]]*/g;
Newstr=str.replace (RegExp, "");
Return NEWSTR
}

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.