Category Archives: Validators

PHP Credit Card Validator – Class

If you ever need to validate credit card numbers, here is a simple validator class. Of course you can use it as simple as just defining validation rules in one array and use the php biult-in preg_match function to validate. But for the sake of good OOP practice, we need a class . Well, i read more »

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

PHP Email Validator

The most common validator – email address validator: <?php $email = "[email protected]"; $pattern = "/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i"; $isValid = preg_match($pattern, $email); ?> Create a simple validation function, so you can use it as many times you need: <?php function validateEmail($email) { $pattern = "/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i"; return preg_match($pattern, $email); } ?> You can check more examples at http://php.net/manual/en/function.preg-match.php .

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS