Javascript code _ javascript skills that are commonly used to restrict input

Source: Internet
Author: User
Js Code that is commonly used to restrict input

1. when the cancel button is pressed, add the value hideFocus or HideFocus = true <input type = "submit" value = "submit" hidefocus = "true"/> 2 to the input box. read-only text box content, add the attribute value readonly in input <input type = "text" readonly/> 3. prevent TEXT files from being cleared (style content can be referenced as a class) <input type = "text" style = "behavior: url (# default # savehistory ); "/> 4. the ENTER key allows the cursor to move to the next input box <input type = "text" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "/> 5. only Chinese (with flashing) <input type = "text" onkeyup = "Value = value. replace (/[-~] /G, '')" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "/> 6. only numbers (with flashing) <input type = "text" onkeyup = "value = value. replace (/[^ \ d]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')"/> 7. it can only be a number (no flashing) <input type = "text" style = "ime-mode: disabled" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "onkeypress =" if (event. keyCode <48 | event. keyCode> 57) ev Ent. returnValue = false "/> 8. only English and numbers (with flashing) can be entered. <input type = "text" onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')"/> 9. blocked input Method <input type = "text" name = "url" style = "ime-mode: disabled" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 "/> 10. only 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 type = "text" 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} "/>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.