-1

次のような名前をチェックしようとしているvtypeがあります。

99ボールSRL

My-Company SA

会社SA

1つだけを許可するvtypeが必要です。または-または一度にスペース。したがって、My--Companyは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);
},

それは機能ですか?それは私が見たことのない方法で宣言されています。

4

1 に答える 1

0

解決策を見つけ、グローバル一致の「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\-\.\ ]')
  });
于 2012-10-01T19:15:02.430 に答える