A Sample Form Element Validation Function : Form Validation « Form « PHP






A Sample Form Element Validation Function

 
<?php
    function phone_validate($data, $desc) {
        $regex = "/^\([2-9][0-9]{2}\)[2-9][0-9]{2}-[0-9]{4}/i";
        if(preg_match($regex, $data) != 1) {
            return "The '$desc' field isn't valid!";
        }
        return true;
    }
?>
  
  








Related examples in the same category

1.Form value validation: not empty
2.Form Data Validation With Error Count
3.Displaying error messages with the form
4.Elementary Form Validation
5.Form Example for the Form Validator Script
6.Validating form data