Use js regular expression to control the input tag to only allow input values

Source: Internet
Author: User

Style = "ime-mode: Disabled"
This sentence is more practical. To disable the input method. It saves some people the trouble of entering numbers in full angles, and the result cannot be entered to find you crying. It is also a blame for your poor design.

Only numbers are allowed.
Copy codeThe Code is as follows:
<Input name = "username" type = "text" onkeyup = "value = this. value. replace (// D +/g,'') ">

Only English letters, numbers, and underscores (_) are allowed)
Copy codeThe Code is as follows:
<Input name = "username" type = "text" style = "ime-mode: disabled">
<Input name = "username" type = "text" onkeyup = "value = value. replace (/[^/w/. //]/ig,'') ">

Only English letters, numbers, and @ can be entered @
Copy codeThe Code is as follows:
<Input name = "username" type = "text" onkeyup = "value = value. replace (/[^/w = @ &] | _/ig,'') ">

Only Chinese characters are allowed.
Copy codeThe Code is as follows:
<Input name = "username" type = "text" onkeyup = "value = value. replace (/[^/u4E00-/u9FA5]/g,'') ">

Example: Restrict three inputs to numbers or '.' and disable the input method in the input.
Copy codeThe Code is as follows:
<Th style = "width: 60px;"> discount </th>
<SPAN style = "WHITE-SPACE: pre">
</SPAN> <td> <input name = "discountNum" class = "easyui-validatebox" maxlength = "3" style = "ime-mode: disabled "onkeyup =" value = this. value. replace (/[^ \ d.] /g, '')" data-options = "required: 'true', missingMessage: 'Enter the discount number'"/>
<SPAN style = "WHITE-SPACE: pre">
</SPAN> </td>

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.