简体   繁体   中英

Validate id number in php

The form of html format as shown as below:

 <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>

How can an id number (eg A1234) be validated in PHP format?

Simply regex to accept one upper char and four digits should be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM