简体   繁体   中英

Match a text box prompt input to a regex pattern

I have this code, where I want to check two textbox prompts in Cognos and match it to a regular expression. This works if I want to check for only numbers and use isNaN() in the second if statement. But it doesn't work when I want to match it to a regularexpression. And I don't know why that is.

oCR = cognos.Report.getReport('_THIS_');
    var f1 = oCR.prompt.getControlByName('prompt1');
    var f2 = oCR.prompt.getControlByName('prompt2');
    var prompts = [f1,f2];

    for (var i=0;i < prompts.length;i++) {
            prompts[i].setValidator(validate);
    }

function validate(values) {
    var result = false;
    var pattern = /[A-Z]{4}\d{2}/;
    if (values.length > 0) {
        if (values[0].use == pattern) {
            result = true;
       }
    }
    return result;
}
if (values[0].use.match(pattern))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM