using uCalcSoftware; var uc = new uCalc(); static void IsValidEmail(uCalc.Callback cb) { var email = cb.ArgStr(1); var uc = cb.uCalc; // Simple validation: check for '@' and '.' var isValid = uc.EvalStr("Contains('" + email + "', '@') And Contains('" + email + "', '@')"); if (isValid == "true") { cb.ReturnBool(true); } else { cb.ReturnBool(false); } } // 1. Define the custom validation function in the uCalc engine uc.DefineFunction("IsValidEmail(email As String) As Bool", IsValidEmail); // 2. Create and configure the transformer using (var t = new uCalc.Transformer(uc)) { // 3. Define the sanitization and validation rules t.FromTo("user = {val};", "User: {val},"); t.FromTo("age = {val};", "Age: {val},"); t.FromTo("status = {val}", "Status: {@Eval: UCase(val)}"); // Last rule, no trailing comma // The email rule uses the custom function for validation t.FromTo("email = {val};", "Email: {val} {@Eval: IIf(IsValidEmail(val), '(Valid)', '(INVALID)')},"); // 4. Define the messy input strings var input1 = "user= Alice ; age= 30 ; email= alice@ucalc.com ; status=active"; var input2 = "user= Bob; age= 45; email= bob-at-ucalc ; status=inactive"; // 5. Run the transformations Console.WriteLine(t.Transform(input1)); Console.WriteLine(t.Transform(input2)); };