I want to validate a textbox to accept only phone number that starts with either 05 or 966. Any ideas how can I do that? My condition does NOT work it will not Validate the entered data.
This is my textbox
$mform->addElement('text', 'phone', get_string('StudentUpdatePhoneNumber'), $attributes);
function validation($data, $files) {
global $CFG, $DB;
$errors = parent::validation($data, $files);
if (empty($data['phone'])) {
$errors['phone']= get_string('ErrorEmptyPhoneNumber');
}
else if ( !is_numeric ($data['phone'])) {
$errors['phone']= get_string('ErrorNotNumPhoneNumber');
}
else if(preg_match("^[966](.*)$", $data['phone'])) {
$errors['phone']= get_string('ErrorStartWithPhoneNumber');
}
return $errors;
}