Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.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
html表单编号验证php_Php_Html_Forms_Validation - Fatal编程技术网

html表单编号验证php

html表单编号验证php,php,html,forms,validation,Php,Html,Forms,Validation,我想验证表单中的数字。表格应仅以5 6 7 8开头的数字通过,长度应为8。这是我的密码 <?php session_start(); $fecha=date("Y.m.d"); $numero = $_SESSION["numero"]; if(filter_var($numero, strlen($numero ==8),FILTER_VALIDATE_INT) AND in_array(substr($numero, 0, 1), array(5,6, 7, 8))) { $c

我想验证表单中的数字。表格应仅以5 6 7 8开头的数字通过,长度应为8。这是我的密码

<?php
session_start();
$fecha=date("Y.m.d");
$numero = $_SESSION["numero"];
if(filter_var($numero, strlen($numero ==8),FILTER_VALIDATE_INT) AND in_array(substr($numero, 0, 1), array(5,6, 7, 8))) {
    $conexion = mysql_connect("server","user","pass") or die (mysql_error()); mysql_select_db('db',$conexion) or die(mysql_error());
    $result = mysql_query("INSERT INTO `db`.`Incoming` (ID ,MsgExternalID ,MsgFrom ,MsgTo ,MsgBody ,MsgBodyType ,MsgTag ,MsgPriority ,MsgDLRRequested ,MsgOriginatedTime ,MsgScheduledTime ,MsgExpiringTime) VALUES (NULL ,  '0', '+506$numero', '+8384', '', '0', '', NULL , NULL , NULL , NULL , NULL)", $conexion); 
    if($result!=NULL)
    {
        header('Location: page.php');
    }
}else{
    echo '<script language="javascript">';
    echo 'alert("Ingrese un número valido");';
    echo 'history.back()';
    echo '</script>';
}
?>

如果我理解正确只想验证数字?
试试这个基本的正则表达式

if (preg_match('/^[5-8][\d]{7}$/', $numero ))
{
    //DO OPERATIONS HERE...
}

您的代码看起来容易受到sql注入的攻击。使用PDO或mysqli,但不要使用mysql:)谢谢您的建议:)