Regex 公司名称的Vtype

Regex 公司名称的Vtype,regex,Regex,我有一个vtype试图检查名称,如: 99球SRL 我的公司 美国公司 我需要vtype只允许一个。或-或一次一个空间。所以,我的公司会返回false 这就是我所做的,但它不起作用: var alfanumericoTest = new RegExp('^[A-Za-z0-9]*-?\.? '); Ext.apply(Ext.form.field.VTypes, { // vtype validation function alfanumerico: function(val,

我有一个vtype试图检查名称,如:

99球SRL

我的公司

美国公司

我需要vtype只允许一个。或-或一次一个空间。所以,我的公司会返回false

这就是我所做的,但它不起作用:

var alfanumericoTest = new RegExp('^[A-Za-z0-9]*-?\.? ');
Ext.apply(Ext.form.field.VTypes, {
    //  vtype validation function
    alfanumerico: function(val, field) {
        return alfanumericoTest.test(val);
    },
    // vtype Text property: The error text to display when the validation function returns false
    alfanumericoText: 'Ingrese palabras.',
    // vtype Mask property: The keystroke filter mask
    alfanumericoMask: new RegExp('[A-Za-z0-9]|-|\.| ')
});
还有,这意味着什么

alfanumerico: function(val, field) {
      return alfanumericoTest.test(val);
},

这是函数吗?它是以我从未见过的方式声明的。

我找到了解决方案,并为全局匹配添加了“g”修饰符

// Alfanumerico
  var alfanumericoTest = new RegExp('^[A-Za-z0-9]+\.?\-? ?','g');
  Ext.apply(Ext.form.field.VTypes, {
    //  vtype validation function
    alfanumerico: function(val, field) {
      return alfanumericoTest.test(val);
    },
    // vtype Text property: The error text to display when the validation function returns false
    alfanumericoText: 'Ingrese palabras.',
    // vtype Mask property: The keystroke filter mask
    alfanumericoMask: new RegExp('[A-Za-z0-9\-\.\ ]')
  });