正則:文本框只能輸入數字,最多4位小數


<script type="text/javascript">
    function _v(str){
	var v4 = /^[+-]?\d+\.\d{0,4}$/i;
	return v4.test(str);
    }
    document.writeln("1.1111:"+_v("1.1111"));//true
    document.writeln("<br />");
    document.writeln("1.111:"+_v("1.111"));//true
    document.writeln("<br />");
    document.writeln("1.11:"+_v("1.11"));//true
    document.writeln("<br />");
    document.writeln("1.1:"+_v("1.1"));//true
    document.writeln("<br />");
    document.writeln("11.1:"+_v("11.1"));//true
    document.writeln("<br />");
    document.writeln("111.1:"+_v("111.1"));//true
    document.writeln("<br />");
    document.writeln("1111.1:"+_v("1111.1"));//true
    document.writeln("<br />");
    document.writeln("1.11111:"+_v("1.11111"));//false
    document.writeln("<br />");
    document.writeln("58.62596:"+_v("58.62596"));//false
    document.writeln("<br />");
    document.writeln("58.6260:"+_v("58.6260"));//true
    document.writeln("<br />");
    document.writeln("1.1.11.:"+_v("1.1.11."));//false
</script>

  1.1111:true
  1.111:true
  1.11:true
  1.1:true
  11.1:true
  111.1:true
  1111.1:true
  1.11111:false
  58.62596:false
  58.6260:true
  1.1.11.:false


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM