Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中文本框中的数字验证_Php_Post - Fatal编程技术网

PHP中文本框中的数字验证

PHP中文本框中的数字验证,php,post,Php,Post,我需要验证文本框的值。文本框用于客户电话号码,格式为0123456789,仅限10个号码,这意味着在输入号码时,用户不允许添加任何字母或特殊符号 数据通过forms POST方法发送到页面validate.php 我想要一个只接受10个数字的函数,不接受字母或字符。例如,您可以使用preg\u match preg_match('/^[0-9]{10}$/', $_POST['your-value']); 例如,您可以使用preg_match preg_match('/^[0-9]{10}$/

我需要验证文本框的值。文本框用于客户电话号码,格式为0123456789,仅限10个号码,这意味着在输入号码时,用户不允许添加任何字母或特殊符号

数据通过forms POST方法发送到页面validate.php


我想要一个只接受10个数字的函数,不接受字母或字符。

例如,您可以使用preg\u match

preg_match('/^[0-9]{10}$/', $_POST['your-value']);

例如,您可以使用preg_match

preg_match('/^[0-9]{10}$/', $_POST['your-value']);

如前所述,您可以在PHP脚本中使用正则表达式,也可以使用jQuery的validate插件阻止用户提交表单

HTML


如前所述,您可以在PHP脚本中使用正则表达式,也可以使用jQuery的validate插件阻止用户提交表单

HTML


更多信息,请访问。

我认为这对您很有用:

<html>
<head>
<script type="application/javascript">

  function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

</script>
</head>

<body>
    <input type="text" name="tel_num" value="" onkeypress="return isNumberKey(event)" maxlength="10"/>
</body>
</html>

我认为这会对你有用:

<html>
<head>
<script type="application/javascript">

  function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

</script>
</head>

<body>
    <input type="text" name="tel_num" value="" onkeypress="return isNumberKey(event)" maxlength="10"/>
</body>
</html>

试试这个。它验证每个键输入上的条目

HTML:

一旦输入了非数字输入且长度限制为10,它将立即删除该输入


希望这有帮助。

试试这个。它验证每个键输入上的条目

HTML:

一旦输入了非数字输入且长度限制为10,它将立即删除该输入


希望这有帮助。

使用正则表达式-类似于\d{10}thnx bro。。。我已经这么做了,但它不允许我在进入现场时继续生活?我认为您应该对“live”使用客户端验证,我指的是JavaScript。@viru___很棒-看看线程-使用正则表达式-类似于\d{10}thnx bro。。。我已经这么做了,但它不允许我在进入现场时继续生活?我认为您应该对“live”使用客户端验证,而客户端,我指的是JavaScript。@viru_d_好极了-看看这么多线程-
<input size="10" maxlength="10" type="text" name="p_len" id="p_len" value="" onkeyup="check(this)" />
function check(o) {
    v=o.value.replace(/^\s+|\s+$/,''); // remove any whitespace
    if(o=='') {
        return;
    }
    v=v.substr(v.length-1);
    if(v.match(/\d/g)==null) {
        o.value=o.value.substr(0,o.value.length-1).replace(/^\s+|\s+$/,'');
    }
}