Home > Web Front-end > JS Tutorial > js function code to limit text box to integer and currency_form special effects

js function code to limit text box to integer and currency_form special effects

WBOY
Release: 2016-05-16 18:18:43
Original
873 people have browsed it

Limited to integers

<html>
<head>
<script language="javascript" type="text/javascript">
 var G=document.getElementById;
 function checkNumber(){
  var reg = /^(&#63;:0|[1-9][0-9]&#63;|100)$/;
   
  var strNumber = G("txtNumber").value;
  alert(reg.test(strNumber))
 }
</script>
</head>
<body >
<input type="text" value="" id="txtNumber" title="Please enter a number witch between 0 and 100 ..">
<button onclick="checkNumber();">CheckNumber</button>
</body>
</html>
Copy after login

Limited to currency

<script language="JavaScript" type="text/javascript">
<!--
function checkMoney(obj){
var tempValue=obj.value.replace(/(^\s+)|(\s+$)/g,'');
if(!tempValue){return;}
if(/^-&#63;\d+(\.\d+)&#63;$/.test(tempValue)){
obj.value=parseFloat(tempValue).toFixed(2);
}else{
alert('请输入合法的货币值!');
obj.select();
return;
}
}
//-->
</script>
onblur="checkMoney(this)"
Copy after login
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