开发者

How does Sencha Touch matcher work?

I am trying to create a simple matcher that matches any string consisting of alphanumeric characters. I tried the following:

    Ext.reg开发者_如何学CModel('RegistrationData', {
        fields: [
            {name: 'nickname',type: 'string'},
        ],

        validations: [
            {type: 'format', name: 'nickname', matcher: /[a-zA-Z0-9]*/}
        ]
    });

However this does not work as expected. I did not find any documentation on how should a regular expression in a matcher look like.

Thank you for help.


I found a blog on sencha.com, where they explain the validation.

I have no idea what sencha-touch is, but maybe it helps, when you tell us what you are giving to your regex, what you expect it to do, and what it actually does (does not work as expected is a bit vague). According to the blog it accepts "regular expression format", so for your simple check, it should be pretty standard.

EDIT:

As a wild guess, maybe you want to use anchors to ensure that the name has really only letters and numbers:

/^[a-zA-Z0-9]*$/

^ is matching the start of the string

$ is matching the end of the string


Your current regex /[a-zA-Z0-9]*/ would match a string containing zero or more occurrences of lower or upper case characters (A-Z) or numbers anywhere in the string. That's why Joe#2, J/o/e, *89Joe as well as Joe, Joe24andjOe28` match - they all contain zero or more subsequent occurrences of the respective characters.

If you want your string to contain only the respective characters you have to change the regex according to stema's answer:

/^[a-zA-Z0-9]*$/

But this has still one problem. Due to the * which meas zero or more occurrences it also matches an empty string, so the correct string should be:

/^[a-zA-Z0-9]+$/

with + meaning one or more occurrences. This will allow nicknames containing only one lowercase or uppercase character or number, such as a, F or 6.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜