表单? 当在cnic字段中输入时应该是14个数字,但是输出应该像12345-67891023-4这个deshes应该在输出中自动添加如何才能超过这个?
<form method="get" action="example1.php">
Name : <input type="text" name="fname" value="" >
<br>
Last Name : <input type="text" name="lname" value="">
<br>
CNIC # <input type="text" name="cnic" value="">
<br>
Email : <input type="text" name="email" value="">
<br>
Contact # <input type="text" name="contact" value="">
<br>
<input type="submit" name="submit" value="submit">
</form>
<?php
if(isset($_GET['submit'])){
$name =$_GET['fname'];
$lname = $_GET['lname'];
$cnic = $_GET['cnic'];
$email = $_GET['email'];
$contact = $_GET['contact'];
$patternn = "/[A-Za-z]/";
$a = preg_match($patternn,$name);
if ($a){
echo "<br>First Name : ".$name;
}
else {
echo "<br>please enter name";
}
$patterln = "/[a-z]/";
$b = preg_match($patterln,$lname);
if ($b){
echo "<br>Last Name : ".$lname;
}
else {
echo "<br> please enter last name";
}
$patternnic = "/[0-9]{14}/";
$c = preg_match($patternnic,$cnic);
if ($c){
echo "<br> NIC: ".$cnic;
}
else {
echo "<br> please enter nic";
}
$patterne = "/[a-z]/";
$d= preg_match($patterne,$email);
if ($d){
echo "<br> Email : ".$email;
}
else {
echo "<br>please enter email";
}
$patternc = "/[0-9]/";
$e = preg_match($patternc,$contact);
if ($e){
echo "<br> Contact : ".$contact;
}
else {
echo "<br>please enter name";
}
}
?>
如果任何一个字段为空或未正确填充,则不应提交表单?