hi there,
how do i validate names like surname and first name with the preg_match function???

Depends on how you think your users first name and surname would be.
For example, let's say the first name would be a single word, 4 to 20 letters and surname would be one or two words, each between 3 to 20 letters.
You would have something like this:

<?php
$name = 'Jackson';
$surname = 'George Michael';
if (preg_match ('/^[a-z]{4,20}$/i',$name)) {
 echo "Good name";
 }
else {
 echo "Bad name";
 }
 
if (preg_match ('/^[a-z]{3,20}(| [a-z]{3,20})$/i',$surname)) {
 echo "Good surname";
 }
else {
 echo "Bad surname";
 }

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.