dsaob80228 2014-10-20 13:37
浏览 21
已采纳

拆分输入与银行编号一起使用(输入拆分为部分)

I do not seem to be able to find an answer for this, though likely I am looking at the wrong thing. I currently have a Yii application where I am able to create accounts and store peoples data. One such piece of data is a persons IBAN number. Currently I have a single text input where people can type the country code and the 22 digits necessary. I am then able to validate this and error or save accordingly. One thing I would like to do is to be able to have a split input box. In a single input an Iban appears like so: ES0012345678912345678912

I would like to split it like so: ES00 1234 5678 91 2345678912

This makes it much more user friendly and easy to read. I can certainly change the way it looks on the view but when editing I would like to have five input boxes in a single row, one takes 4, the next one 4 characters, the next one 4 etc. An example of what I mean:

enter image description here

Can someone please point me in the direction of how this is achieved. Is there a type of split input I can use, or do I need to create 5 separate inputs and simply join them on submission and validate from here? The ability to simply split the saved entry across these 5 boxes would be much easier.

Many Thanks

  • 写回答

1条回答 默认 最新

  • dongzhi5386 2014-10-20 13:58
    关注

    As a suggestion, if you use a model, simply add your attributes like below:

    Class ModelName extends CActiveRecord {
        public $ibanNumber;
    
        public $ibanNumberPart1;
        public $ibanNumberPart2;        
        public $ibanNumberPart3;
        public $ibanNumberPart4;
    
    public function beforeValidate(){
        if(parent::beforeValidate()){
            $this->ibanNumber=$this->ibanNumberpart1.$this->ibanNumberPart2 ...
            return true;
        }    
    }
    
    //then write rules and so on
    ...}
    

    By adding $ibanNumberPart1..4 properties to your model, it will know all of them as model attribute. So you can add 4 fields in your view with name ibanNumberPart1 and so on. It is also possible to write validations rules for each attribute. For example:

    public function rules(){
        return array(
            array('ibanNumberPart1','required'),
            array('ibanNumberPart1','numerical','integerOnly'=>true),
        );
    }    
    

    By this, you split your input into 4 parts, and finally you have all of them into 1 field called $ibanNumber.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害