Create a static class such as ReqFunctions. Make the methods as static and then you can call them from the form that you are working.
for example on top of my head:
class ReqFunctions
{
public static bool ValidateTextBox(string txtBoxValue, string validationType)
{
if(validatioType == "Number")
{
Regex isnumber = new Regex("[^0-9]");
return !isnumber.IsMatch(txtBoxValue);
}
if(validationType == "Char")
{
Regex ischar = new Regex("^[a-zA-Z]+$");
return !ischar.IsMatch(txtBoxValue);
}
}
}
In your code you can call this function as
ReqFunctions.ValidateTextBox(txtTextbox1.Text);
You can also check this
MSDN link[
^].
Recently I have found this also:
Numbers and Characters only Textbox Validation in C# ![
^]