Implement validation check for grid locator input

This commit is contained in:
phl0
2022-03-28 12:41:14 +02:00
parent f17f148d01
commit c5ff0df369
2 changed files with 25 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ class QSO extends CI_Controller {
$this->form_validation->set_rules('start_date', 'Date', 'required');
$this->form_validation->set_rules('start_time', 'Time', 'required');
$this->form_validation->set_rules('callsign', 'Callsign', 'required');
$this->form_validation->set_rules('locator', 'Locator', 'callback_check_locator');
if ($this->form_validation->run() == FALSE)
{
@@ -443,4 +444,26 @@ class QSO extends CI_Controller {
header('Content-Type: application/json');
echo $input;
}
function check_locator($grid) {
$grid = $this->input->post('locator');
// Allow empty locator
if (preg_match('/^$/', $grid)) return true;
// Allow 6-digit locator
if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Ra-r]{2}$/', $grid)) return true;
// Allow 4-digit locator
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true;
// Allow 4-digit grid line
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true;
// Allow 4-digit grid corner
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2},[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true;
// Allow 2-digit locator
else if (preg_match('/^[A-Ra-r]{2}$/', $grid)) return true;
// Allow 8-digit locator
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Ra-r]{2}[0-9]{2}$/', $grid)) return true;
else {
$this->form_validation->set_message('check_locator', 'Please check value for grid locator ('.strtoupper($grid).').');
return false;
}
}
}

View File

@@ -158,7 +158,8 @@
<label for="locator" class="col-sm-3 col-form-label"><?php echo $this->lang->line('gen_hamradio_locator'); ?></label>
<div class="col-sm-9">
<input type="text" class="form-control form-control-sm" name="locator" id="locator" value="">
<small id="locator_info" class="form-text text-muted">Enter multiple (4-digit) grids separated with commas. For example: IO77,IO78</small>
<small id="locator_info" class="form-text text-muted"></small>
<small id="locator_format" class="form-text text-muted">Enter multiple (4-digit) grids separated with commas. For example: IO77,IO78</small>
</div>
</div>