When we talk about validations, we can think of the fields of a form the fastest, which need certain restrictions.
- The field must necessarily contain values:
1 2 3 4 |
IF(EMPTY($nume) || STRLEN($nume)<1) { $msje['nume_msj'] = "Name is required!"; } |
- Fields containing only text characters:
1 2 3 4 5 6 7 8 9 10 |
$msje = array(); $alfa_txt = "/^[a-zA-Z ]+$/"; //.......... IF(!preg_match($alfa_txt, $nume)) { $msje['nume_msj'] = "Only text characters are allowed"; $nume = ""; } //.......... <!--?php echo $msje['gdpr_msj']; ?--> |
- Fields containing only numeric values:
1 2 3 4 5 |
IF(!is_numeric($telefon)) { $msje['tel_msj'] = "The phone can contain only numerical values"; $telefon = 0; } |
The field must have a certain number of characters:
1 2 3 4 |
IF(STRLEN($cnp) !== 13) { $msje['cnp_msj'] = "ID must be 13 digits!"; } |