Home > Web Front-end > JS Tutorial > Various verification text box input formats implemented by js regular expressions

Various verification text box input formats implemented by js regular expressions

不言
Release: 2018-08-15 18:00:01
Original
2405 people have browsed it

The content of this article is about the various verification text box input formats implemented by js regular expressions. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

cannot be empty

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

Only English and numbers can be entered

<input onblur="if(/[^0-9a-zA-Z]/g.test(value))alert(&#39;有错&#39;)">
<input onkeyup="value=value.replace(/[^0-9a-zA-Z]/g,&#39;&#39;)"/>
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9]/g,&#39;&#39;)">
Copy after login

The judgment characters are composed of letters and numbers, underscores, and periods. And the beginning can only be an underscore and a letter

/^([a-zA-z_]{1})([\w]*)$/g.test(str)
Copy after login

Only numbers can be entered

<input name="text" type="text" id="NewPage" onKeyUp="value=value.replace(/\D/g,&#39;&#39;)" onafterpaste="value=value.replace(/\D/g,&#39;&#39;)" >
Copy after login

Can only enter Chinese

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

Can only enter English

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

Only Chinese, English, numbers, @ symbols and . symbols can be input

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

Only English input is allowed, and neither paste nor pop-up of the paste menu is allowed

<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

Only numbers and periods can be entered (note: the d in [^\d\.] cannot be written as a capital D, otherwise it will become all characters except numbers)

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

In short: first enter onkeyup="value=value.replace(/[^\X]/g,'')" in and then in (/[\X]/g, '') just replace the

##English

: a-z, A-ZOther symbols@, dot or other symbols. You can also have multiple, just separate them with \.For example:
Chinese, English and numbers Add the @ symbol and the dot symbol: \a-\z\A-\Z0-9\u4E00-\u9FA5\@\.If you want to not be able to right-click the pop-up menu in the text box and paste the copied information If so, enter

 onKeyDown="fncKeyStop(event)" onpaste="return false" oncontextmenu="return false;"
Copy after login
in Related recommendations:

JS verification of regular expressions

js regular expression verification time format example

The above is the detailed content of Various verification text box input formats implemented by js regular expressions. 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