作成日: 2018/05/16 最終更新日: 2018/05/16
文書種別
使用方法
詳細
バイト単位で入力可能な文字列を制限する組み込みの機能はございませんが、標準のCustomValidatorと組み合わせることで、クライアント側でバイト単位で入力を制限できます。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
------------------------
Webフォームクラス
------------------------
' テキスト型セルの設定
Dim tCell As FarPoint.Web.Spread.TextCellType = New FarPoint.Web.Spread.TextCellType
FpSpread1.ActiveSheetView.Columns(0).CellType = tCell
' CustomValidatorの設定
Dim cValidator As CustomValidator = New CustomValidator
cValidator.ValidateEmptyText = false
cValidator.ClientValidationFunction = "ClientValidate"
cValidator.ErrorMessage = "5バイト以内"
tCell.Validators.Add(cValidator)
------------------------------------
クライアント側スクリプト
------------------------------------
<script type="text/javascript">
function ClientValidate(source, arguments) {
if (getByte(arguments.Value) <= 5) {
arguments.IsValid = true;
} else {
arguments.IsValid = false;
}
}
function getByte(text) {
count = 0;
for (i = 0; i < text.length; i++) {
n = escape(text.charAt(i));
if (n.length < 4) count++; else count += 2;
}
return count;
}
</script>
Webフォームクラス
------------------------
' テキスト型セルの設定
Dim tCell As FarPoint.Web.Spread.TextCellType = New FarPoint.Web.Spread.TextCellType
FpSpread1.ActiveSheetView.Columns(0).CellType = tCell
' CustomValidatorの設定
Dim cValidator As CustomValidator = New CustomValidator
cValidator.ValidateEmptyText = false
cValidator.ClientValidationFunction = "ClientValidate"
cValidator.ErrorMessage = "5バイト以内"
tCell.Validators.Add(cValidator)
------------------------------------
クライアント側スクリプト
------------------------------------
<script type="text/javascript">
function ClientValidate(source, arguments) {
if (getByte(arguments.Value) <= 5) {
arguments.IsValid = true;
} else {
arguments.IsValid = false;
}
}
function getByte(text) {
count = 0;
for (i = 0; i < text.length; i++) {
n = escape(text.charAt(i));
if (n.length < 4) count++; else count += 2;
}
return count;
}
</script>
◎サンプルコード(C#)
-------------------------------
Webフォームクラス
-------------------------------
// テキスト型セルの設定
FarPoint.Web.Spread.TextCellType tCell = new FarPoint.Web.Spread.TextCellType();
FpSpread1.ActiveSheetView.Columns[0].CellType = tCell;
// CustomValidatorの設定
CustomValidator cValidator = new CustomValidator();
cValidator.ValidateEmptyText = false;
cValidator.ClientValidationFunction = "ClientValidate";
cValidator.ErrorMessage = "5バイト以内";
tCell.Validators.Add(cValidator);
------------------------
クライアント側スクリプト
------------------------
※VBのサンプルコードと同様
Webフォームクラス
-------------------------------
// テキスト型セルの設定
FarPoint.Web.Spread.TextCellType tCell = new FarPoint.Web.Spread.TextCellType();
FpSpread1.ActiveSheetView.Columns[0].CellType = tCell;
// CustomValidatorの設定
CustomValidator cValidator = new CustomValidator();
cValidator.ValidateEmptyText = false;
cValidator.ClientValidationFunction = "ClientValidate";
cValidator.ErrorMessage = "5バイト以内";
tCell.Validators.Add(cValidator);
------------------------
クライアント側スクリプト
------------------------
※VBのサンプルコードと同様
旧文書番号
82678