Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-06-24 12:11:45955browse

What should I do if I want to restrict the input of specific numbers, such as only 0 and 1?
71d8e911276bfdc8c63daaba723aa016How 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 = '';	}}

Statement:
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