I am trying to write some dynamic code , where each control's value will go through set of regular expressions attached to it.
In order to achieve so I have created a XML which will represent which all Regex will be applied to its values. Sample XML:
<control name="firstname">
<validationtype ="regex:'. ">
<validationtype ="regex:a-zA-Z">
</control>
I am trying to read the XML in c# code where I loop thru validationtype
and adding in to the List<string>
List<string> validations = new List<string>();
foreach(var item in vaildationtype)
{
if(item.contains("regex:")
{
validations.add(item.text.split(':')[1]);
}
}
Above code when try to add regex expression like ".' " in to List<string>
throwing object reference not set to an instance of object error
Appreciate your pointers.
UPDATE: so some guys are actually deviated from my ask: here is what I am after.
I have an array of strings in which I store all the regex that was passed by another program. A program passes the values as "regex:a-zA-z
", "regex:0-9
", "regex:.'
" etc
I want to store all the expressions into List<string>
object by splitting the values passed by a program. So, In my list I want to store "a-zA-z", "0-9" etc.
but, it is throwing object reference not set to an instance".