Top > SAStrutsあれこれ > アノテーションバリデーション集

Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = "^[\u0020-\u007E]+$", msg = @Msg(key = "errors.ascii"))
    public String asciiText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = "^[\u3040-\u309F]+$", msg = @Msg(key = "errors.hiragana"))
    public String hiraganaText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = "^[\u30A0-\u30FF]+$", msg = @Msg(key = "errors.katakana"))
    public String katakanaText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = "^[\uFF65-\uFF9F]+$", msg = @Msg(key = "errors.halfKatakana"))
    public String halfKatakanaText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = "^[\uFF01-\uFF60]+$", msg = @Msg(key = "errors.fullWidthAscii"))
    public String fullWidthAsciiText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = "^[^ -~。-゚]*$", msg = @Msg(key = "errors.fullWidth"))
    public String fullWidthText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = ".*[^\u0020-\u007E].*", msg = @Msg(key = "errors.existNoAscii"))
    public String existNoAsciiText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = ".*[^A-Za-z].*", msg = @Msg(key = "errors.existNoArpha"))
    public String existNoArphaText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = ".*[^0-9].*", msg = @Msg(key = "errors.existNoDigit"))
    public String existNoDigitText;
Everything is expanded.Everything is shortened.
  1
  2
  3
 
 
 
    @Required
    @Mask(mask = ".*[\uFF65-\uFF9F].*", msg = @Msg(key = "errors.existHalfKatakana"))
    public String existHalfKatakanaText;
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 
 
 
 
 
 
 
-
|
|
|
|
|
|
-
|
|
!
|
|
-
|
!
!
package tutorial.action;
 
import javax.annotation.Resource;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import tutorial.form.ValidatorExtForm;
 
public class ValidatorExtAction {
 
    @ActionForm
    @Resource
    protected ValidatorExtForm validatorExtForm;
 
    @Execute(validator = false)
    public String index() {
        validatorExtForm.initialize();
        return "index.jsp";
    }
 
    @Execute(input = "index.jsp")
    public String submit() {
        return "index.jsp";
    }
}
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
!
!
package tutorial.form;
 
import org.seasar.struts.annotation.Mask;
import org.seasar.struts.annotation.Msg;
import org.seasar.struts.annotation.Required;
 
public class ValidatorExtForm {
 
    /**
     * 文字列が「ASCII文字」のみか?
     */
    @Required
    @Mask(mask = "^[\u0020-\u007E]+$", msg = @Msg(key = "errors.ascii"))
    public String asciiText;
 
    /**
     * 文字列が「ひらがな」のみか?
     */
    @Required
    @Mask(mask = "^[\u3040-\u309F]+$", msg = @Msg(key = "errors.hiragana"))
    public String hiraganaText;
 
    /**
     * 文字列が「カタカナ」のみか?
     */
    @Required
    @Mask(mask = "^[\u30A0-\u30FF]+$", msg = @Msg(key = "errors.katakana"))
    public String katakanaText;
 
    /**
     * 文字列が「半角カタカナ」のみか?
     */
    @Required
    @Mask(mask = "^[\uFF65-\uFF9F]+$", msg = @Msg(key = "errors.halfKatakana"))
    public String halfKatakanaText;
 
    /**
     * 文字列が「全角ASCII文字」のみか?
     */
    @Required
    @Mask(mask = "^[\uFF01-\uFF60]+$", msg = @Msg(key = "errors.fullWidthAscii"))
    public String fullWidthAsciiText;
 
    /**
     * 文字列が「全角文字」のみか?
     */
    @Required
    @Mask(mask = "^[^ -~。-゚]*$", msg = @Msg(key = "errors.fullWidth"))
    public String fullWidthText;
 
    /**
     * 文字列にASCII文字でない文字が存在するか?
     */
    @Required
    @Mask(mask = ".*[^\u0020-\u007E].*", msg = @Msg(key = "errors.existNoAscii"))
    public String existNoAsciiText;
 
    /**
     * 文字列に半角英字でない文字が存在するか?
     */
    @Required
    @Mask(mask = ".*[^A-Za-z].*", msg = @Msg(key = "errors.existNoArpha"))
    public String existNoArphaText;
 
    /**
     * 文字列に半角数字でない文字が存在するか?
     */
    @Required
    @Mask(mask = ".*[^0-9].*", msg = @Msg(key = "errors.existNoDigit"))
    public String existNoDigitText;
 
    /**
     * 文字列に半角カタカナが存在するか?
     */
    @Required
    @Mask(mask = ".*[\uFF65-\uFF9F].*", msg = @Msg(key = "errors.existHalfKatakana"))
    public String existHalfKatakanaText;
 
    public void initialize() {
        asciiText = "abcdbbbb!\"#$%&'()=~|-^\\@[;:],./<>?_}*+`{";
        hiraganaText = "あいうえおかきくけこをんがぽ";
        katakanaText = "アイウエオ";
        halfKatakanaText = "アイウエオザジズゼゾ";
        fullWidthAsciiText = "ABCDEF@!+*_";
        fullWidthText = "さにわらがな感じAAAAA●@「」:lp¥^0998";
        existNoAsciiText = "abcdefあ";
        existNoArphaText = "%ABCDEFGHIJKLMN";
        existNoDigitText = "a3333333";
        existHalfKatakanaText = "abアcdef";
    }
}
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<title>Tutorial: Validator</title>
<link rel="stylesheet" type="text/css" href="${f:url('/css/sa.css')}" />
</head>
<body>
<h1>Tutorial: Validator Extension</h1>
 
<html:errors/>
<s:form>
<table>
<tr>
<td>ASCII文字:</td><td><html:text property="asciiText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>全角ひらがな:</td><td><html:text property="hiraganaText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>全角カタカナ:</td><td><html:text property="katakanaText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>半角カタカナ:</td><td><html:text property="halfKatakanaText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>全角ASCII文字:</td><td><html:text property="fullWidthAsciiText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>全角文字:</td><td><html:text property="fullWidthText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>非ASCII文字:</td><td><html:text property="existNoAsciiText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>非半角英字:</td><td><html:text property="existNoArphaText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>非半角数字:</td><td><html:text property="existNoDigitText" errorStyleClass="err" /></td>
</tr>
<tr>
<td>文字列中に半角カタカナが存在するか?:</td><td><html:text property="existHalfKatakanaText" errorStyleClass="err" /></td>
</tr>
</table>
<input type="submit" name="submit" value="サブミット"/>
</s:form>
</body>
</html>
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 
 
 
 
 
 
 
 
 
 
errors.ascii=全てASCII文字で入力して下さい。
errors.hiragana=全て全角ひらがなで入力して下さい。
errors.katakana=全て全角カタカナで入力して下さい。
errors.halfKatakana=全て半角カタカナで入力して下さい。
errors.fullWidthAscii=全て全角ASCII文字で入力して下さい。
errors.fullWidth=全て全角文字で入力して下さい。
errors.existNoAscii=ASCII文字ばかりです。非ASCII文字を混ぜましょう。
errors.existNoArpha=半角英字ばかりです。非半角英字を混ぜましょう。
errors.existNoDigit=半角数字ばかりです。非半角数字を混ぜましょう。
errors.existHalfKatakana=半角カタカナはありませんでした。

リロード   新規 編集 凍結解除 差分 添付 複製 名前変更   ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2012-08-08 (水) 23:26:12 (2923d)