RegExpValidator永远不匹配 [英] RegExpValidator never matches

查看:144
本文介绍了RegExpValidator永远不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有说的意思来验证输入字段,以确保该值始终是一个十进制的类。我在这里测试的正则表达式:的http://的LiveDocs .adobe.com /柔性/ 3 / HTML / help.html?内容= validators_7.html ,它看起来像它做了正确的事情,但在我的应用程序,我似乎无法得到它的匹配为数字格式。

I've got a class that's meant to validate input fields to make sure the value is always a decimal. I've tested the regex here: http://livedocs.adobe.com/flex/3/html/help.html?content=validators_7.html, and it looks like it does the right thing, but in my app, I can't seem to get it to match to a number format.

类定义:

public class DecimalValidator {
    //------------------------------- ATTRIBUTES
    public var isDecimalValidator:RegExpValidator;

    //------------------------------- CONSTRUCTORS
    public function DecimalValidator() { 
        isDecimalValidator                  = new RegExpValidator();
        isDecimalValidator.expression       = "^-?(\d+\.\d*|\.\d+)$";
        isDecimalValidator.flags            = "g";
        isDecimalValidator.required         = true;
        isDecimalValidator.property         = "text";
        isDecimalValidator.triggerEvent     = FocusEvent.FOCUS_OUT;
        isDecimalValidator.noMatchError     = "Float Expected";
    }

}

设置源位置:

Setting the source here:

public function registerDecimalInputValidator(inputBox:TextInput, valArr:Array):void  {
        // Add Validators
        var dValidator:DecimalValidator = new DecimalValidator();
        dValidator.isDecimalValidator.source = inputBox;
        dValidator.isDecimalValidator.trigger = inputBox;

        inputBox.restrict = "[0-9].\\.\\-";
        inputBox.maxChars = 10;

        valArr.push(dValidator.isDecimalValidator);
    }

和调用在这里:

registerDecimalInputValidator(textInput, validatorArr);

在哪里与textInput是先前创建一个输入框。

Where textInput is an input box created earlier.

显然我失去了一些东西简单而重要的,但我不能完全肯定的!任何帮助将是非常美联社preciated。

Clearly I'm missing something simple yet important, but I'm not entirely sure what! Any help would be much appreciated.

推荐答案

我不知道动作,但据我所知这是一个ECMAScript语言,所以我希望你需要的,如果你使用一个字符串来逃避反斜杠定义一个正则表达式:

I don't know ActionScript, but as far as I know it's an ECMAScript language, so I expect you need to escape the backslashes if you use a string to define a regex:

isDecimalValidator.expression       = "^-?(\\d+\\.\\d*|\\.\\d+)$";

这篇关于RegExpValidator永远不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆