0

Here are two simple functions to validate name and e-mail .

int valName( string $arg1 )

- this function returns 1 if name is correct, 0 if incorrect

int valMail( string $arg1 )

- this function returns 1 if name is correct, 0 if incorrect

// valName()

function valName($name) 

{
      $name = preg_replace(‘/[\s]+/is’, ‘ ‘, $name);
      $name = trim($name);

      return preg_match(‘/^[a-z\s]+$/i’, $name);            
}


// valMail()

function valMail($email)
{ 

 $regexp='/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';
 
 return preg_match($regexp, trim($email));

}
1
Contributor
0
Replies
20
Views
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.