Jump to content

Serial number validation


xiao

Recommended Posts

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Ā  ;D

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.