How do I use the TextCondition Regex (regular expression)

Posted by: ampires9 on 16 December 2018, 12:20 am EST

    • Post Options:
    • Link

    Posted 16 December 2018, 12:20 am EST

    Hello,

    Looking at the following schema page of Spread.Sheets (http://help.grapecity.com/spread/SpreadSheets11/webframe.html#fullschema11.html) you’ll notice a ‘regex’ property on the TextCondition. I can’t find any examples in the documentation on how to use regular expressions in a text condition. My initial thought was to do something like this:

    new Condition(ConditionType.textCondition, { regex: new RegExp('some_pattern') })
    

    But that didn’t work. What’s the correct use of regex in a text condition?

    Thanks.

  • Posted 18 December 2018, 1:19 am EST

    Hello,

    You can use the code as follows to create regex validator:

    
    var nCondition = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.textCondition);
                nCondition.compareType(GC.Spread.Sheets.ConditionalFormatting.TextCompareType.contains);
                var patt1 = /test/;
                nCondition.regex(new RegExp(patt1));
                var validator = new GC.Spread.Sheets.DataValidation.DefaultDataValidator(nCondition);
                validator.type(GC.Spread.Sheets.DataValidation.CriteriaType.custom);
                activeSheet.getCell(1, 1, GC.Spread.Sheets.SheetArea.viewport).validator(validator);
                spread.options.highlightInvalidData = true;
    activeSheet.setValue(1, 1, "testing");
    
    

    Thanks,

    Deepak Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels