Home > Web Front-end > JS Tutorial > Code example sharing for JS verification input box (letters, numbers, symbols, Chinese)

Code example sharing for JS verification input box (letters, numbers, symbols, Chinese)

黄舟
Release: 2017-03-24 14:28:40
Original
1971 people have browsed it

This article mainly introduces the method of JS to verify the input input box (letters, numbers, symbols, Chinese). Has very good reference value. Let’s take a look with the editor below

Only English can be entered

<input type="text" onkeyup="value=value.replace(/[^a-zA-Z]/g,&#39;&#39;)">
Copy after login

Only English can be entered

<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,&#39;&#39;)"
onkeydown="fncKeyStop(event)" onpaste="return false"
oncontextmenu="return false" />
Copy after login

Unable to paste, right-click will not pop up the paste menu

Only numbers can be entered:

<input onkeyup="this.value=this.value.replace(/\D/g,&#39;&#39;)"
onafterpaste="this.value=this.value.replace(/\D/g,&#39;&#39;)">
Copy after login

Only numbers and decimal points can be entered :

<input name="price" type="text"
onkeyup="value=value.replace(/[^\d\.]/g,&#39;&#39;)">
Copy after login

Only numbers, decimal points, and underscores can be entered:

<input name="price" type="text"
onkeyup="value=value.replace(/[^\d\._]/g,&#39;&#39;)">
Copy after login

Only English and numbers can be entered:

<input onkeyup="value=value.replace(/[\W]/g,&#39;&#39;) "
onbeforepaste="clipboardData.setData(&#39;text&#39;,clipboardData.getData(&#39;text&#39;).replace(/[^\d]/g,&#39;&#39;))">
Copy after login

Only Chinese characters can be input:

<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,&#39;&#39;)"
onbeforepaste="clipboardData.setData(&#39;text&#39;,clipboardData.getData(&#39;text&#39;).replace(/[^\u4E00-\u9FA5]/g,&#39;&#39;))">
Copy after login

Input method input is prohibited:

<input type="text" style="ime-mode: disabled">
Copy after login

Cannot switch input method

Only Chinese, English, numbers, @ symbols and . symbols can be entered:

<input type="text"
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.]/g,&#39;&#39;)">
Copy after login

Cannot be empty:

<input 
onblur
="
if
(this.value.replace(/^ +| +$/g,&#39;&#39;)==&#39;&#39;)alert(&#39;不能为空!&#39;)">
Copy after login

The above is the detailed content of Code example sharing for JS verification input box (letters, numbers, symbols, Chinese). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template