Regex validation with examples using php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
// Validation for characters- it will allow only letters and spaces //sample entry : hello vasanthan if (!preg_match("/^[a-zA-Z\s]+$/", $name)) { echo 'Enter characters for Name'; } //Validation for time-it will validate the time format as hh:mm //sample entry : 01:09 if (!preg_match("/^(([0-1][0-9])|(2[0-3])):[0-5][0-9]$/", $time)) { echo 'Enter valid format for example hh:mm'; } //valdiation of numbers //sample entry : 10 if (!preg_match("/^[1-9]+$/", $hours)) { echo 'Enter digits as hours'; } |