扩展extjs中的电子邮件验证 [英] extending email validation in extjs
问题描述
我正在使用6.0.1.250版本的ExtJs内置的以下用户注册表格.我有一个电子邮件字段,可以接受 .co
, .com
,直到四个字符为止.我需要处理最近的 tlds
,并希望覆盖电子邮件验证逻辑.我尝试使用 validator
并应用了正则表达式,但是 regexText
不支持国际化.如何扩展 email
验证.我正在使用extjs框架的6.0版本.以下是UserForm的代码段
I am having the below user registration form built in 6.0.1.250 version of ExtJs. I have an email field which accepts .co
,.com
till the four characters. I need to handle the recent tlds
and want to override the email validation logic. I tried with the validator
and applying the regex but the regexText
is not supporting internationalisation. How to extend the email
validation. I am using 6.0 version of extjs framework. Below is the code snippet for UserForm
Ext.define('myApp.view.users.NewUserForm', {
extend: 'Ext.panel.Panel',
xtype: 'newuser',
title: '<span class="red-label">*</span>'+ l10n('new-user'),
items: [{
xtype: 'textfield',
fieldLabel: '<span class="red-label">*</span>' + l10n('name'),
name: 'username',
maxLength: 80,
allowBlank: false
}, {
xtype: 'textfield',
inputType: 'password',
fieldLabel: '<span class="red-label">*</span>' + l10n('password'),
name: 'password1',
vtype: 'password',
initialPassField: 'password2',
allowBlank: false,
maskRe: /[^ ]/
}, {
xtype: 'textfield',
fieldLabel: '<span class="red-label">*</span>' + l10n('confirm-password'),
vtype: 'password',
inputType: 'password',
name: 'password2',
initialPassField: 'password1',
allowBlank: false,
maskRe: /[^ ]/
}, {
xtype: 'textfield',
fieldLabel: '<span class="red-label">*</span>' + l10n('e-mail-address'),
name: 'emailAddress',
vtype:'email',
allowBlank: false
}, {
xtype: 'textarea',
fieldLabel: l10n('description'),
name: 'userDescription'
}]
});
推荐答案
您可以像这样覆盖电子邮件验证vtype:
You could override the email validation vtype like so:
Ext.define(null, {
override: 'Ext.form.field.VTypes',
email: function (value) {
return /^(")?(?:[^\."\s])(?:(?:[\.])?(?:[\w\-!#$%&'*+/=?^_`{|}~]))*\1@(\w[\-\w]*\.){1,5}([A-Za-z]){2,10}$/.test(value);
}
});
我使用了默认的电子邮件正则表达式,并进行了更改,以便域名允许2到10个字符.
I took the default email regex and changed so that it allows from 2 to 10 characters for the domain name.
修改
如果使用Sencha CMD,则有一个特殊的 overrides
文件夹,您应在其中放置替代项.因此,您可以创建一个名为 Vtypes.js
的文件,然后将代码放在该文件中,然后在 sencha应用刷新
之后就可以了.如果不这样做,则应该在使用实际vtype之前基本执行覆盖.您可能在 Application.js
中有一个名为 applyOverrides
的方法,然后从您的
If you use Sencha CMD, there is a special overrides
folder where you should put your overrides. So you can create a file called Vtypes.js
, place the code there, and after a sencha app refresh
you will be fine. If you don't - the override should be basically executed before you use the actual vtype. You might have a method called applyOverrides
in your Application.js
, and then call it first thing from your launch method.
这篇关于扩展extjs中的电子邮件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!