Common HTML Regular Expressions
1. Only numbers and English letters can be entered:
Copy codeThe Code is 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 codeThe Code is 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 fullwidth fields can be entered:
Copy codeThe Code is 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 can be entered:
Copy codeThe Code is 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 codeThe Code is 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 ("enter a valid and valid email address! ")
Return false;
}
6. ID card:
Copy codeThe Code is as follows:
"^ // D {17} (// d | x) $"
7.17 Regular Expressions
Copy codeThe Code is 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 + )? $ "// Non-negative floating point number (Positive 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] *) $ "// 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 consisting of 26 English letters
"^ [A-Z] + $" // a string consisting of 26 uppercase letters
"^ [A-z] + $" // a string consisting of 26 lowercase letters
"^ [A-Za-z0-9] + $" // string consisting of digits and 26 letters
"^ // W + $" // a string consisting of digits, 26 English letters, or underscores
"^ [// W-] + (//. [// w-] +) * @ [// w-] + (//. [// w-] +) + $ "// email address
"^ [A-zA-z] +: // (// w + (-/w + )*)(//. (// w + (-/w + )*))*(//? // S *)? $ "// Url
========================================================== =====
1. The dotted box when the cancel button is pressed
Add the attribute value hideFocus or HideFocus = true in input.
2. Read-only text box content
Add the attribute value readonly in input.
3. Prevent TEXT files from being cleared (style content can be referenced as a class)
<INPUT style = behavior: url (# default # savehistory); type = text
Id = oPersistInput>
4. Press ENTER to move the cursor to the next input box.
<Input onkeydown = "if (event. keyCode = 13) event. keyCode = 9">
5. It can only be Chinese (with flashing)
Copy codeThe Code is as follows:
<Input onkeyup = "value ="/value. replace (/["-~] /G ,'')"
Onkeydown = "if (event. keyCode = 13) event. keyCode = 9">
6. Only numbers are allowed (with flashing)
Copy codeThe Code is as follows:
<Input onkeyup = "value ="/value. replace (/["^/d]/g ,'')
"Onbeforepaste =" clipboardData. setData ('text', clipboardData. getData ('text'). replace (/[^/d]/g, '')">
7. Only numbers are allowed (no flashing)
Copy codeThe Code is 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. Only English and numbers can be entered (with flashing)
Copy codeThe Code is as follows:
<Input onkeyup = "value ="/value. replace (/[/W]/g ,"'')"
Onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text'). replace (/[^/d]/g,'') ">
9. shielded Input Method
Copy codeThe Code is as follows:
<Input type = "text" name = "url" ime-mode: disabled"
Onkeydown = "if (event. keyCode = 13) event. keyCode = 9">
10. You can only enter numbers, decimal points, minus (-) characters (no flashing)
Copy codeThe Code is as follows:
<Input onKeyPress = "if (event. keyCode! = 46 & event. keyCode! = 45 &&
(Event. keyCode <48 | event. keyCode> 57) event. returnValue = false ">
11. Only two decimal places can be entered, and three decimal places (with flashing)
Copy codeThe Code is 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>