カスタムバリデータのスクリプトの例

カスタムスクリプトバリデータの例を示します。次の例が含まれます。
次のスクリプトは、基本のカスタムバリデータで、第 5 桁と最初の 4 桁を取得してそれらを変数に割り当て、予測される datalength とこれらの値を比較することで 5 桁のデータ識別子を検証します。
基本のカスタムスクリプトバリデータ
パラメータ
説明
パターン
\d{5}
正規化群
なし
カスタムスクリプト
$s1 = getStringValueAt($normalizedMatch, 0x4,1); // Get the 5th digit $s2 = getStringValueAt($normalizedMatch, 0x0,4); // Get the first 4 digits $size1 = datalength($s1);// Calculate the length; it should be 1 $size2 = datalength($s2);// Calculate the length; it should be 4 assertTrue($size1 == 1); // Check if size = 1 assertFalse($size2 != 4); // Check if size is anything other than 4
次のカスタムスクリプトは LL/MM/DD/YYYY の形式の 10 文字の文字列を検証します。最初の 2 文字はその人のイニシャルで、検証から除外されます。残りの桁は別の変数に保存され、乗数によって計算されて追加されます。その後、適切な日 (32 未満)、月 (13 未満)、年 (2051 未満) に従っているかを確認するために比較されます。
10 文字のカスタムスクリプトバリデータ
パラメータ
説明
パターン
\l{2}\d{8}
正規化群
数字と英字
カスタムスクリプト
$m1 = getIntegerAt($normalizedMatch, 0x2, 1); $m2 = getIntegerAt($normalizedMatch, 0x3, 1); $d1 = getIntegerAt($normalizedMatch, 0x4, 1); $d2 = getIntegerAt($normalizedMatch, 0x5, 1); $y1 = getIntegerAt($normalizedMatch, 0x6, 1); $y2 = getIntegerAt($normalizedMatch, 0x7, 1); $y3 = getIntegerAt($normalizedMatch, 0x8, 1); $y4 = getIntegerAt($normalizedMatch, 0x9, 1); $m1 = multiply($m1, 10); $d1 = multiply($d1, 10); $y1 = multiply($y1, 1000); $y2 = multiply($y2, 100); $y3 = multiply($y3, 10); $Day = Add($d1, $d2); $Month = Add($m1, $m2); $Year = Add($y1, $y2, $y3, $y4); assertTrue($Day > 0); assertTrue($Day <= 31); assertTrue($Month > 0); assertTrue($Month <= 12); assertTrue($Year >= 1910); assertTrue($Year <= 2050);
次のカスタムスクリプトバリデータはトルコの ID 番号の一致を検証するために使うことができます。トルコの ID は 11 桁の番号です。最初の桁にはゼロを含めることはできません。第 10 桁と第 11 桁は誤り検出用のチェックデジットです。
トルコの ID のカスタムスクリプトバリデータ
パラメータ
説明
パターン
\d{11}
正規化群
数字のみ
カスタムスクリプト
$k1 = getIntegerAt($normalizedMatch, 0x0, 1); $k2 = getIntegerAt($normalizedMatch, 0x1, 1); $k3 = getIntegerAt($normalizedMatch, 0x2, 1); $k4 = getIntegerAt($normalizedMatch, 0x3, 1); $k5 = getIntegerAt($normalizedMatch, 0x4, 1); $k6 = getIntegerAt($normalizedMatch, 0x5, 1); $k7 = getIntegerAt($normalizedMatch, 0x6, 1); $k8 = getIntegerAt($normalizedMatch, 0x7, 1); $k9 = getIntegerAt($normalizedMatch, 0x8, 1); $c1 = getIntegerAt($normalizedMatch, 0x9, 1); $c2 = getIntegerAt($normalizedMatch, 0xA, 1); $iOdds = add($k1, $k3, $k5, $k7, $k9); $iEvens = add($k2, $k4, $k6, $k8); $iOddsMltSeven = multiply($iOdds, 7); $iEvensMltNine = multiply($iEvens, 9); $iOddsMltEight = multiply($iOdds, 8); $iMidSum = add($iOddsMltSeven, $iEvensMltNine); $iCheck1 = mod($iMidSum, 10); assertTrue($iCheck1 == $c1); $iCheck2 = mod($iOddsMltEight, 10); assertTrue($iCheck2 == $c2);