如何在 extjs 中的文本字段正则表达式中粘贴一些文本后验证文本字段的值?

发布于 2025-01-04 09:51:35 字数 885 浏览 2 评论 0 原文

在我的应用程序中,有一个文本字段,其中只允许使用正则表达式:/[A-Z0-9_]/。 当我们使用下面粘贴的代码从键盘输入值时,它工作正常。 问题是当我使用 ctrl+v 和右键粘贴接受粘贴正则表达式以外的某些值时。 注意我禁用了右键单击和按下按键时的 ctrl+v 事件,这对于我的问题来说不是一个好的解决方案,请帮助我解决这个问题。 请告诉我如何在粘贴一些文本后验证文本字段的值。

          Mycode: { 
                    xtype: 'textfield',
                    flex: 1,
                    allowBlank: false,
                    maskRe: /[A-Z0-9_]/,
                    maxLength: 50,
                    regex: /[A-Z0-9_]/,
                    ref: '../refField',
                    enableKeyEvents:true,
                    listeners: {
                        keydown: function(field, e){
                            if((e.getKey() ==86) && e.ctrlKey){
                                e.stopEvent();

                            }
                        }
                    }
                }

问候, 拉吉

In my application a text field is there where only regex: /[A-Z0-9_]/ should be allowed.
its working fine when we enter values from key board with the code i pasted below.
Problem is when i paste some value other than regex is being accepted using ctrl+v and rightclick paste.
NoteI disabled right click and ctrl+v events on key down which is not good solution for my problem please help me in solving this..
please tell me how to validate the value of text field after pasting some text .

          Mycode: { 
                    xtype: 'textfield',
                    flex: 1,
                    allowBlank: false,
                    maskRe: /[A-Z0-9_]/,
                    maxLength: 50,
                    regex: /[A-Z0-9_]/,
                    ref: '../refField',
                    enableKeyEvents:true,
                    listeners: {
                        keydown: function(field, e){
                            if((e.getKey() ==86) && e.ctrlKey){
                                e.stopEvent();

                            }
                        }
                    }
                }

Regards,
raj

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法言说的痛 2025-01-11 09:51:35

您可以尝试在 keyup 事件上调用 validate 方法,如下所示:

http://www.sencha.com/forum/showthread.php?27147-Trying-to-get-extjs-to-react-to-text-changing-on-a-text-field< /a>

但正如他们所说,它不能保证这在所有浏览器中都有效。在我看来,100% 的解决方案是在 blur 事件中的字段上调用 ​​validate() 。

像这样的东西:

combo.on('blur', funciton(field){
    !if(field.isValid()){
         //do what you need, for example clean the value in the field
    }
})

You could try call validate method on the keyup event, as suggested here:

http://www.sencha.com/forum/showthread.php?27147-Trying-to-get-extjs-to-react-to-text-changing-on-a-text-field

But as they say, it wont guarantee that this will work in all browsers. In my view 100% solution is to call validate() on field in the blur event.

something like:

combo.on('blur', funciton(field){
    !if(field.isValid()){
         //do what you need, for example clean the value in the field
    }
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文