Home > Web Front-end > HTML Tutorial > How to use regular expressions to limit the input of text boxes_html/css_WEB-ITnose

How to use regular expressions to limit the input of text boxes_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:11:45
Original
979 people have browsed it

What should I do if I want to restrict the input of specific numbers, such as only 0 and 1?
How to restrict it


Reply to discussion (solution)

<input type="text" name="text" id="demo" /><script type="text/javascript">document.getElementById('demo').onchange = function() {	if (!/^[01]+$/.test(this.value)) {		alert('非法字符');		this.value = '';	}}
Copy after login

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