Home  >  Article  >  Web Front-end  >  The simplest JavaScript to verify integers, decimals, real numbers, significant decimal regular expressions_javascript skills

The simplest JavaScript to verify integers, decimals, real numbers, significant decimal regular expressions_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:03:161183browse
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title> 验证数字最简单正则表达式大全 </title> 
</head> 
<body> 
<h3>输入完按回车后即可验证!(自认为最简单!)</h3> 
正整数:  <input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^/d+$/.test(this.value));" /> 
<br /> 
负整数:  <input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^-/d+$/.test(this.value));" /> 
<br /> 
整 数:  <input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^-&#63;/d+$/.test(this.value));" /> 
<br /> 
正小数:  <input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^/d+/./d+$/.test(this.value));" /> 
<br /> 
负小数:  <input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^-/d+/./d+$/.test(this.value));" /> 
<br /> 
小 数:  <input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^-&#63;/d+/./d+$/.test(this.value));" /> 
<br /> 
实 数:  <input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^-&#63;/d+(/./d+)&#63;$/.test(this.value));" /> 
<br /> 
保留1位小数:<input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^-&#63;/d+(/./d{1,1})&#63;$/.test(this.value));" /> 
<br /> 
保留2位小数:<input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^-&#63;/d+(/./d{1,2})&#63;$/.test(this.value));" /> 
<br /> 
保留3位小数:<input type="text" size="20" onkeydown="if(event.keyCode == 13) alert(/^-&#63;/d+(/./d{1,3})&#63;$/.test(this.value));" /> 
<br /> 
</body> 
</html> 

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