js验证,代码如下:
- <script type="text/javascript">
 - var dnum=document.getElementById("fenshu");
 - dnum.onkeyup = function(){
 - this.value=this.value.replace(/D/g,'');
 - if(dnum.value>1000||dnum.value<100){
 - dnum.value=100;
 - }
 - }
 - </script>
 
php验证,代码如下:
- $var=300;
 - $int_options = array(
 - "options"=>array
 - (
 - "min_range"=>0,
 - "max_range"=>256
 - )
 - );
 - if(!filter_var($var, FILTER_VALIDATE_INT, $int_options))
 - {
 - echo("Integer is not valid");
 - }
 - else
 - {//开源代码Vevb.com
 - echo("Integer is valid");
 - }
 
方法三js
php正则:^([1-9][0-9][0-9]|1000)$
这里我们主要是用到了正则表达式来完成,验证数字是否在指定的数据间距之间.
新闻热点
疑难解答