The regular expression restricts that only numbers and English letters can be entered in the input box.

Source: Internet
Author: User
Tags valid email address

 

Common HTML Regular Expressions 1. Only numbers and English characters can be entered:
<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:
<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-width fields can be entered:
<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:
<Input onkeyup = "value = value. Replace (/[^/u4e00-/u9fa5]/g ,'')"
Onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text'). Replace (/[^/u4e00-/u9fa5]/g ,''))"
Id = "text4" name = "text4"> 5. Verify the email address:
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 | com | Gov | mil | org | Edu | 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:
"^ // D {17} (// d | x) $"
7.17 Regular Expressions
"^ // 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)
<Input onkeyup = "value ="/value. Replace (/["-~] /G ,'')"
Onkeydown = "If (event. keycode = 13) event. keycode = 9">

6. Only numbers are allowed (with flashing)
<Input onkeyup = "value ="/value. Replace (/["^/d]/g ,'')
"Onbeforepaste =" clipboardData. setdata ('text', clipboardData. getdata ('text'). Replace (/[^/d]/g, '')">
7. Only numbers are allowed (no flashing)
<Input ime-mode: Disabled"
Onkeydown = "If (event. keycode = 13) event. keycode = 9" onkey PRESS = "If
(Event. keycode <48 | event. keycode> 57) event. returnvalue = false ">

8. Only English and numbers can be entered (with flashing)
<Input onkeyup = "value ="/value. Replace (/[/W]/g ,"'')"
Onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text'). Replace (/[^/d]/g,'') ">
9. shielded Input Method
<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)
<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)
<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>

 

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.