问题
How do I get my regular expression code working on my dojo cellWidget object? I'm trying to get this regex working in two places, one with an IP address and another just a simple number field for values between 0 and 3000 but no matter what I try it seems to not like anything. Sometimes I can type a single digit number and I don't get my validation message, otherwise I always get the validation message on both of these. I am using a dijit/form/ValidationTextBox for this
Here is my code:
{ id: 'numberId', field: 'numberColumn', name: 'Number', width: '150px',
widgetsInCell: true,
navigable: true,
setCellValue: function(gridData, storeData, cellWidget){
var rowIndex = cellWidget.cell.row.index()+1;
var toggle = numberGridx.model.store.get(rowIndex).numberColumn;
cellWidget.numberColumn.set('regExp', "(100)|(0*\d{1,2})");
cellWidget.numberColumn.set('style', "width:115px");
cellWidget.numberColumn.set('invalidMessage', "Dude that won't work!");
},
decorator: function(){
return "<input type='text' data-dojo-type='dijit/form/ValidationTextBox' data-dojo-attach-point='numberColumn' />";
}
},
My other cellWidget regex code is here (Tried all these):
// cellWidget.outProActFeedsDestAddr.set('regExp', "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\$");
// cellWidget.outProActFeedsDestAddr.set('regExp', "m/^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/");
cellWidget.outProActFeedsDestAddr.set('regExp', "([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])");
回答1:
Well, this one worked from my coworker no doubt (I had tried something similar, but I think the double '\'s is what solved it:
"([01]?\d\d?|2[0-4]\d|25[0-5])..."
cellWidget.outProActFeedsDestAddr.set('regExp', "([01]?\\d\\d?|2[0-4]\\d|25[0-5])[.]([01]?\\d\\d?|2[0-4]\\d|25[0-5])[.]([01]?\\d\\d?|2[0-4]\\d|25[0-5])[.]([01]?\\d\\d?|2[0-4]\\d|25[0-5])");
来源:https://stackoverflow.com/questions/29216116/how-do-i-get-my-regular-expression-code-working-on-my-dojo-cellwidget-object