js controls the character type method summary for text box input

  • 2020-06-15 07:46:25
  • OfStack

JS control text boxes 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 Numbers, decimal points


<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 be entered in English


<input onkeyup="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 and Numbers


<input onkeyup="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,'')">

The JS control text box can only be entered in Chinese


<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onpaste="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" oncontextmenu="value=value.replace(/[^\u4E00-\u9FA5]/g,'')">

The JS control text box can only enter Chinese, English and Numbers


<input onkeyup="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 enter Chinese, English, Numbers, space


<input onkeyup="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, decimal point


<input onkeyup="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,'')">

To sum up:

In the first ' < input > 'in the input

onkeyup="value=value.replace(/[^\X]/g,'')"

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

Chinese u4E00-u9FA5, Numbers 0-9, English ES68en-ES69en \ ES70en-ES71en, other symbols @, dot or other symbols.

Can also be multiple, with \ space on the line.
For example: Chinese and English + digit + @ symbol + dot symbol \ ES75en-\ ES77en-\ Z0-9\u4E00-\u9FA5\@\.

If you can't right-click in a text field to bring up a menu and can't paste in copied information

In ' < input > 'onpaste="return false" oncontextmenu="return false;"


Related articles: