Implement validation check for grid locator input

这个提交包含在:
phl0 2022-03-28 12:41:14 +02:00
父节点 f17f148d01
当前提交 c5ff0df369
找不到此签名对应的密钥
GPG 密钥 ID: 48EA1E640798CA9A
共有 2 个文件被更改,包括 25 次插入1 次删除

查看文件

@ -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;
}
}
}

查看文件

@ -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>