xiao Posted December 15, 2007 Share Posted December 15, 2007 I have this PHP-book, and after every chapter there are exercises, but there aren't any solutions online, so I'm gonna ask you gurusĀ I had to make a regex for a serial number: A16B947-c All characters can go from a to z, all numbers from 0 to 9, there's a difference between caps and no caps. This is what I had: <?php function valid_serial($str){ return(ereg('^[A-Z][0-9]{2}[A-Z][0-9]{3}-[a-z]',$str)); } ?> <form method="post" action="p97-1.php"> Serienummer: <input type="text" name="serial" /> <input type="submit" value="Valideren" name="valideren" /> </form> <?php if(isset($_POST['valideren'])){ $str = $_POST['serial']; $output = valid_serial($str); if($output == FALSE){ echo "<b>Fout!</b>"; } if($output == TRUE){ echo "<b>Juist!</b>"; } } Link to comment https://forums.phpfreaks.com/topic/81851-serial-number-validation/ Share on other sites More sharing options...
effigy Posted December 16, 2007 Share Posted December 16, 2007 Add a $ at the end of the pattern. Link to comment https://forums.phpfreaks.com/topic/81851-serial-number-validation/#findComment-415951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.