请问在PHP中怎么规定某个输入值格式为分数格式?或者说表达式是怎么样的?我现在想实现在输入框中只能输入类似于1/2这样的格式,其他格式提示输入不对。请问我该怎么表达?谢谢!php分数格式 

解决方案 »

  1.   


    具体的判断语句怎么写呢?刚学PHP还请指教,谢谢!
      

  2.   

    以下是一个例子,供参考。
    <script>
    function foo(){
        var v=document.getElementById('demo').value;
    var p=/\d+\/\d+/;
    if(!p.test(v)){
        alert('格式不正确');
        return false;
    }
         return true;
    }
    </script>
    <form action="" method="post" onsubmit="return foo()">
    <input type="text" id="demo">
    <input type="submit" value="submit" >
    </form>