The JS control text box can only enter Chinese, English, numeric, and specified special symbols.

Source: Internet
Author: User

Convert the string entered in the input box to a comma with a comma example: <input type= "text" id= "keywords" style= "width:650px;" > JS: With the Lost cursor event, the key code: str.replace (/,/ig, ', '); $ ("#keywords"). blur (function () {
var str = $ ("#keywords"). Val ();
Str=str.replace (/,/ig, ', ');
$ ("#keywords"). Val (str);
});

Word:

Enter in ' <input> ' first

Onkeyup= "Value=value.replace (/[^\x]/g, ')"

Then the X in (/[\x]/g, ") is replaced with the code you want to enter,

Chinese u4e00-u9fa5, number 0-9, English a-z\a-z, other symbols @, dots, or other symbols.

can also be multiple, with \ Separated on the line.
For example: Chinese and English + digit + @ sign + dot symbol \a-\z\a-\z0-9\u4e00-\u9fa5\@\.

If you want to not right-click the popup menu in the text box and cannot paste in the copied information

Enter onpaste= "return false" oncontextmenu= "return false" in ' <input> '. "

‘The S control text box can only enter numbers
<input onkeyup= "Value=value.replace (/[^0-9]/g, ')" onpaste= "Value=value.replace (/[^0-9]/g, ')" OnContextMenu = " Value=value.replace (/[^0-9]/g, ') ">

JS control text box can only enter a number, a decimal point
<inputonkeyup= "Value=value.replace (/[^\0-9\.) /g, "onpaste=" Value=value.replace (/[^\0-9\.) /g, ') "OnContextMenu =" value=value.replace (/[^\0-9\.) /g, ') ' >

JS control text box can only be entered in English
<inputonkeyup= "Value=value.replace (/[^\a-\z\a-\z]/g, ')" onpaste= "Value=value.replace (/[^\a-\z\A-\Z]/g, ')" OnContextMenu = "Value=value.replace (/[^\a-\z\a-\z]/g, ')" >

JS control text box can only input English, digital
<inputonkeyup= "Value=value.replace (/[^\a-\z\a-\z0-9]/g, ')" onpaste= "Value=value.replace (/[^\a-\z\A-\Z0-9]/g , ') "oncontextmenu=" Value=value.replace (/[^\a-\z\a-\z0-9]/g, ') ">

JS control text box can only input Chinese
<inputonkeyup= "Value=value.replace (/[^\u4e00-\u9fa5]/g, ')" onpaste= "Value=value.replace (/[^\u4E00-\u9FA5]/g , ') "oncontextmenu=" Value=value.replace (/[^\u4e00-\u9fa5]/g, ') ">

JS control text box can only input Chinese, English, digital
<inputonkeyup= "Value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5]/g, ')" onpaste= "Value=value.replace (/[^\a- \z\a-\z0-9\u4e00-\u9fa5]/g, ') "OnContextMenu =" value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5]/g, ') ">

JS control text box can only input Chinese, English, numbers, spaces
<inputonkeyup= "Value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5]/g, ')" onpaste= "Value=value.replace (/[^\a- \z\a-\z0-9\u4e00-\u9fa5]/g, ') "OnContextMenu =" value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5]/g, ') ">

JS control text box can only input Chinese, English, digits, decimal point
<inputonkeyup= "Value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5\.) /g, "onpaste=" Value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5\.) /g, ') "OnContextMenu =" value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5\.) /g, ') ' >

The JS control text box can only enter Chinese, English, numeric, and specified special symbols.

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.