- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
11-17-2022 06:50 PM
はじめまして。
現在、Client Scriptで正規表現を用いた入力値のバリデーションを実装しようとしています。
試行錯誤したのですがどうしても意図した動作をしないため、ご相談したく投稿致しました。
バリデーションで満たしたいことは入力値が「半角の数字と大英文字を含む」ことです。(100と100gbはNG、100GBはOK)
下記に作成したスクリプトを記載します。
原因がお分かりになりましたらご教示頂けると幸いです。
宜しくお願い致します。
var re = /^[0-9][A-Z]*$/;
if (!newValue.match(re)){
getMessage("Please enter the storage 1 capacity in uppercase letters and single-byte numbers.(ex 100GB)", function(msg){alert(msg);});
g_form.clearValue('u_storage1_capacity');
}
※ ClientScriptの発動条件はu_storage1_capacityが更新された時です。
※ newValueはユーザーが入力したu_storage1_capacityが入ります。
解決済! 解決策の投稿を見る。
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
11-17-2022 10:07 PM - 編集済み 11-17-2022 10:09 PM
Update the regex like this:
var pattern = new RegExp(/^[0-9]{3}[A-Z]{2}?$/);
Murthy
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
11-17-2022 09:08 PM
以下の更新されたスクリプトを試してみてください。
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = new RegExp(/^[0-9A-Z]+$/);
if (!pattern.test(newValue)) {
alert(getMessage("Please enter the storage 1 capacity in uppercase letters and single-byte numbers." + "(ex 100GB)"));
g_form.clearValue("u_storage1_capacity");
}
}
Murthy
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
11-17-2022 10:01 PM
Hello Murthy.
Thank you for replying.
That's very helpful.
Updated script.
However, it allows "100".
I want to create a script that does not allow "100" or "100gb" but only allows "100GB".
But that is difficult.
Thanks,
Kentaro
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
11-17-2022 10:07 PM - 編集済み 11-17-2022 10:09 PM
Update the regex like this:
var pattern = new RegExp(/^[0-9]{3}[A-Z]{2}?$/);
Murthy
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
11-17-2022 11:46 PM
Hello Murthy.
Thank you for replying.
Problem solved!