Validation Settings
You can write validation scripts to check individual settings. The validation scripts are run after a user enters settings but before the settings are saved.
You can use any of the following languages to write validation scripts:
- VBScript
- JScript
- C#
- VB.net
Use the validation tag to apply a validation script to a setting. Use method to define the validation method name. Use param to define a parameter value to pass to the method or paramval to pass a registry setting value to the method. The validation result is returned by the method’s return value. Use either dotnetscript to define a .net script (C# or VB.net), or script to define a script (VBScript or JScript) to do the validation.
The following segment from an administrative template file illustrates how to call a validation method:
- <validation>
<method name="Validation.CheckUser" />
- <dotnetscript language="C#">
- <code>
- <![CDATA[
public class Validation
{
public static string[] CheckUser(string value)
{
return Utility.CheckUnixNames(value, new
char[] { }, "Unix user name");
}
}
]]>
</code>
</dotnetscript>
</validation>
You place the code to call the method within a CDATA tag. Likewise, place the validation code itself within a CDATA tag, as in the following example:
- <dotnetscript language="C#">
- <code>
- <!--
Validation Utility
-->
- <![CDATA[
using System;
using System.Text;
public class Utility
{
.
.
.
/// <summary>
/// Check for a list of Unix names separated by seps
/// </summary>
/// <param name="value">\</param>
/// <param name="seps">\</param>
/// <param name="displayText"></param>
/// <returns></returns>
public static string[] CheckUnixNames(string value, char[]
seps, string displayText)
{
.
.
.
}
}
]]>
</code>
</dotnetscript>