如何将清晰的复制粘贴数据复制到表单中

How to get clear copy paste data into a form

我不确定这个标题是否是这个问题的正确标题。 我的问题是..有一个表格,需要通过从文档中复制粘贴来填写。

以下是我的代码:

// length of rrnNo = 12 character, could be append with spaces and start with spaces as well 
$RRN = $this->input->post('rrnNo');

// do some search using $RRN
$checkRRN = strpos($text, $RRN)

if ($checkRRN !== FALSE)
{
   print $text;
}

我遇到了一个错误,当用户复制并粘贴整个 12 位数字时,没有显示搜索结果。但是当他们复制并粘贴最后 9 位数字时,他们设法得到了结果。所以我所做的是..

// length of rrnNo = 12 character, could be append with spaces and start with spaces as well  
$RRN = $this->input->post('rrnNo');

// get last 9 digits
$shortRRN = substr($rrn,-9);

// do some search using shortRRN
$checkRRN = strpos($text, $shortRRN)

if ($checkRRN !== FALSE)
{
   print $text;
}

但仍然不适用于 12 位数字。他们仍然需要粘贴 9 位数字的数据才能得到结果。感谢您的 advice/opinion。 谢谢

使用此代码

$RRN = trim($this->input->post('rrnNo',true));
//trim the string to remove spaces before and after, and the second parameter is for xss handling (security) 

if (strpos(trim($text), $RRN) )
{
   print $text;
}

此外,如果您想确保用户提供的字符恰好是 12 个,请加载 form-validation 库并像这样进行快速验证。

$this->form_validation->set_rules('rrnNo',"RNN number",'trim|required|min_length[12]|max_length[12]');
if ($this->form_validation->run()){
  //write your code in here
}