Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.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中验证id号_Php_Regex_Validation - Fatal编程技术网

在php中验证id号

在php中验证id号,php,regex,validation,Php,Regex,Validation,html格式的格式如下所示: <tr style="height:15px;"><td></td></tr> <tr> <td>ID Card No<br /></td> </tr> <tr> <td><input class="input" style="width:300" size="20" type="text" name="id" m

html格式的格式如下所示:

 <tr style="height:15px;"><td></td></tr>
 <tr>
   <td>ID Card No<br /></td>
 </tr>
 <tr>
 <td><input class="input" style="width:300" size="20" type="text" name="id" maxlength="5"/></td>
 </tr>

身份证号码

如何以PHP格式验证id号(如A1234)

简单地用regex接受
一个上字符和四个数字应该是:

$str = 'A1234';
$result = preg_match('~^[A-Z]\d{4}$~', $str);
print_r($result); // true | false

“以PHP格式验证”是什么意思?您希望将其验证为什么?电话号码?电子邮件?验证的标准是什么?您的问题需要更多信息吗?比如你试过什么,你到底想要什么。请详细说明你的问题。。如何验证id字段..1。具有验证规则(@Epodax comment)2。使用
regular expressions
应用这些规则。在输入标记中使用pattern=“[A-Z]{1}\d{4}”,但这是html5验证。我不知道表达式“$str='A1234'mean@user3056561:这是您提供给我们的有问题的输入值。实际上,它将是
$\u POST['id']
$\u GET['id']
,取决于表单的方法属性(值
)。第一行是
$str=$\u GET/POST['id']
。正则表达式不适合我。这是供参考的其他表达式吗?@user3056561:它将在服务器上工作,它是PHP。在浏览器中,您需要使用JS正则表达式,使用相同的模式。请更具体地说明什么对我不起作用。是的,我需要使用JS正则表达式。谢谢