InputMan for ASP.NETの検証コントロールを使用し、入力中にリアルタイムで検証を行えます。入力値を検証し、エラーを通知するほか、不正値の入力を禁止するなどInputMan for ASP.NETの多様な機能を使用したデータ検証を行うことができます。また、検証アクションエクステンダを使用して、色やアイコン、バルーンチップによる視覚的なエラー通知も可能です。
検証に使用できる、InputManの検証コントロールおよび検証アクションエクステンダの一覧は以下のとおりです。
なお、これらの詳細な機能については、InputMan for ASP.NETの製品ヘルプの「検証コントロール」を参照してください。
InputMan検証コントロール一覧
文字種(GcCharacterTypeValidator) |
機能 |
入力した文字の文字種を検証。
全角半角文字、英数字や記号のほか、サロゲートペア文字や環境依存文字の入力制御が可能。 |
使用例 |
・大文字半角アルファベットのみ入力を許可したい。
・サロゲートペア文字を入力させたくない。 |
文字数(GcTextLengthValidator) |
機能 |
入力した文字数が、範囲内にあるかどうか検証。
入力可能な文字数をバイト単位か文字単位かを指定することもできる。 |
使用例 |
・4文字以上8文字以下の入力のみ許可したい。
・2バイト以上、6バイト以下の入力のみ許可したい。 |
日付範囲(GcDateRangeValidator) |
機能 |
入力した日付が、範囲内にあるかどうか検証。 |
使用例 |
・2012/1/1~2012/12/31までの範囲だけ入力を許可したい。 |
日付比較(GcDateDifferenceValidator) |
機能 |
コントロールに入力した日付を、別のコントロールに入力された日付または、指定日付のいずれかと比較検証。
比較対象である2つの日付の差も指定できる。 |
使用例 |
・今日から5日以降の日付は入力させたくない。
・到着日付は出発日付より前に限定したい。 |
禁止文字列(GcForbiddenTextValidator) |
機能 |
入力を禁止するテキストを入力したかどうかを検証。 |
使用例 |
・select、update、deleteなどSQLインジェクションを引き起こす文字列は入力させたくない。
・携帯アドレス(docomo.ne.jpなど)は許可したくない。 |
データ型(GcDataTypeValidator) |
機能 |
入力した文字のデータ型を検証。 |
使用例 |
・日付型の妥当性チェックを行いたい。 |
InputMan検証アクションエクステンダ(GcValidatorAction)機能一覧
色によるエラー通知(ColorNotify) |
不正値が入力された時の背景色と文字色、および正常値が入力された時の背景色と文字色を設定できる。
 |
バルーンチップによるエラー通知(TipNotify) |
バルーンチップに表示するタイトルやテキストのほか、バルーンの背景色、境界色やアイコンも設定できる。
 |
アイコンによるエラー通知(IconNotify) |
アイコンの点滅、アイコン画像やアイコンとコントロールの間隔、アイコンのツールチップ文字列を設定できる。
 |
エラー入力値の処理(ValueProcess) |
入力された値が不正なときに、この値をどのように処理するか設定できる。以下の設定が可能。
・入力された値を保持(Keep)
・入力された値を消去(Clear)
・変更前の値に戻す(Restore) |
InputManの検証機能を設定してから、SPREADのセルに追加します。
SPREAD標準の検証の代わりにInputManの検証機能を使用するには、各セル型のValidators プロパティを使用します。このプロパティは、以下のセル型(編集可能なセル型)に対して使用できます。
検証に失敗した場合は、ErrorMessageShown イベントがクライアント側で発生し、ユーザーはアクティブセルを変更できなくなります。
テキスト型セル(TextCellType)のShowEditor プロパティがTrueに設定されている場合は、検証はサポートされません。
設定方法
- 検証コントロールオブジェクトのインスタンスを生成し、コントロールのIDおよび検証内容を設定します。
- 必要に応じて、検証アクションエクステンダを作成します。
- 生成した検証アクションエクステンダを1.で作成した検証コントロールに追加します。
- ページに検証アクションエクステンダオブジェクトを追加します。
- セルを作成します。
- セルのValidators プロパティに、生成した検証コントロールを追加します。
サンプルコード
次のサンプルコードは、セルを作成して、このセルに基本的な文字数検証コントロール(GcTextLengthValidator)を割り当てます。また、エラー時にはバルーンチップ、アイコンおよび色で通知します。
protected void Page_Load(object sender, EventArgs e)
{
// InputManの設定
GrapeCity.Web.Input.IMValidators.GcTextLengthValidator ct1 = new GrapeCity.Web.Input.IMValidators.GcTextLengthValidator();
ct1.ID = "ct1";
ct1.ValidateOnInput = true;
ct1.ErrorMessage = "";
ct1.MaximumLength = 5;
GrapeCity.Web.Input.IMExtenders.GcValidatorAction GcValidatorAction1 = new GrapeCity.Web.Input.IMExtenders.GcValidatorAction();
GcValidatorAction1.ID = "GcValidatorAction1";
GrapeCity.Web.Input.IMExtenders.TipNotify tip = new GrapeCity.Web.Input.IMExtenders.TipNotify();
tip.ToolTipTitle = "範囲外入力";
tip.ToolTipText = "半角5文字以内で入力してください。";
tip.ToolTipSpan = 20000;
GcValidatorAction1.DefaultActions.Add(tip);
GrapeCity.Web.Input.IMExtenders.IconNotify IconAction1 = new GrapeCity.Web.Input.IMExtenders.IconNotify();
IconAction1.BlinkRate = 500;
IconAction1.BlinkStyle = GrapeCity.Web.Input.IMExtenders.ErrorBlinkStyle.AlwaysBlink;
IconAction1.IconAlignment = GrapeCity.Web.Input.Core.AlignEnum.Right;
IconAction1.IconPadding = 1;
IconAction1.IconTip = "5文字以下";
IconAction1.BlinkStyle = GrapeCity.Web.Input.IMExtenders.ErrorBlinkStyle.NeverBlink;
GcValidatorAction1.DefaultActions.Add(IconAction1);
GrapeCity.Web.Input.IMExtenders.ColorNotify ColorAction1 = new GrapeCity.Web.Input.IMExtenders.ColorNotify();
ColorAction1.InvalidBackColor = System.Drawing.Color.Yellow;
ColorAction1.InvalidForeColor = System.Drawing.Color.Red;
GcValidatorAction1.DefaultActions.Add(ColorAction1);
ct1.ValidatorActionID = "GcValidatorAction1";
this.Page.Form.Controls.Add(GcValidatorAction1);
if (IsPostBack)
{
return;
}
// Inputの検証コントロールを標準型セルに設定
FarPoint.Web.Spread.GeneralCellType gc = new FarPoint.Web.Spread.GeneralCellType();
gc.Validators.Add(ct1);
// B2セルに標準型セルを設定
FpSpread1.ActiveSheetView.Cells[1, 1].CellType = gc;
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' InputManの設定
Dim ct1 As New GrapeCity.Web.Input.IMValidators.GcTextLengthValidator()
ct1.ID = "ct1"
ct1.ValidateOnInput = True
ct1.ErrorMessage = ""
ct1.MaximumLength = 5
Dim GcValidatorAction1 As New GrapeCity.Web.Input.IMExtenders.GcValidatorAction()
GcValidatorAction1.ID = "GcValidatorAction1"
Dim tip As New GrapeCity.Web.Input.IMExtenders.TipNotify()
tip.ToolTipTitle = "範囲外入力"
tip.ToolTipText = "半角5文字以内で入力してください。"
tip.ToolTipSpan = 20000
GcValidatorAction1.DefaultActions.Add(tip)
Dim IconAction1 As New GrapeCity.Web.Input.IMExtenders.IconNotify()
IconAction1.BlinkRate = 500
IconAction1.BlinkStyle = GrapeCity.Web.Input.IMExtenders.ErrorBlinkStyle.AlwaysBlink
IconAction1.IconAlignment = GrapeCity.Web.Input.Core.AlignEnum.Right
IconAction1.IconPadding = 1
IconAction1.IconTip = "5文字以下"
IconAction1.BlinkStyle = GrapeCity.Web.Input.IMExtenders.ErrorBlinkStyle.NeverBlink
GcValidatorAction1.DefaultActions.Add(IconAction1)
Dim ColorAction1 As New GrapeCity.Web.Input.IMExtenders.ColorNotify()
ColorAction1.InvalidBackColor = System.Drawing.Color.Yellow
ColorAction1.InvalidForeColor = System.Drawing.Color.Red
GcValidatorAction1.DefaultActions.Add(ColorAction1)
ct1.ValidatorActionID = "GcValidatorAction1"
Me.Page.Form.Controls.Add(GcValidatorAction1)
If IsPostBack Then
Return
End If
' Inputの検証コントロールを標準型セルに設定
Dim gc As New FarPoint.Web.Spread.GeneralCellType()
gc.Validators.Add(ct1)
' B2セルに標準型セルを設定
FpSpread1.ActiveSheetView.Cells(1, 1).CellType = gc
End Sub