1. ホーム
  2. Web制作
  3. html5

amazeuiのページチェック機能を実装するためのコード

2022-01-11 07:20:44

下図のように

Postal "郵便番号"フィールド、データベース内のvarchar2 (10)。

しかし、amazeuiのページバリデーションでは、文字長に対して以下のようなバリデーションが行われています。

JSフォームバリデーション

JSのフォーム検証は、HTML5の検証属性に基づくものです。

  • required : 必要です。
  • pattern : 正規表現を検証する、プラグインに内蔵された  email , url ,
    number
     three types of regular expressions.
    minlength
    /{code
    maxlength
    : Character limits.
    min
    /{code
    max
    : minimum and maximum limits, applicable only to fields of numeric type.
    minchecked
    /{code
    maxchecked
    : at least, at most, the number of selections that apply to 
    checkbox
    The drop-down multi-select box.
    checkbox
     set the relevant attribute on the first element of the same group.
    .js-pattern-xx
    : Validation rule class, rules that exist in the regular library can be added by adding the corresponding class.
    Note that
    HTML5 native form validation in 
    pattern
     only validates the legitimacy of the value, i.e. it can be left out, and if it is filled in it must conform to the rules. If it is a required field, you still have to add 
    required
     attribute. The plugin is consistent with the HTML5 rules.
    The 
    <! -- The following three ways of writing are equivalent --> <! -- Only the three types of email url number are built-in and can be extended --> <input type="email"/> <! -- js-pattern-xx where xx is the key in the pattern library --> <input type="text" class="js-pattern-email"/> <input type="text" pattern="^(.. .email regex...) $"/> i.e. maxlength=10,amazeui means that you can input 10 characters (numbers, letters, Chinese characters are treated equally. are considered as one word ) But if you enter 10 Chinese characters "中中中中中中中中中中中中中" in the previous paragraph, the database length will definitely overflow after submission, because the length of the field database is varchar2 (10), that is, 10 byte can only store 3.3333 less than 4 Chinese characters (because a Chinese character if GBK/GB2312 encoding takes up 2 bytes, but unicode\utf-8 encoding takes up 3 bytes).
    So maxlength=10 is not the correct limit, but js-pattern-number (this ensures that the input is an integer, so that the Chinese characters will not be entered). Summary This article about the implementation code of the amazeui page check function is introduced to this, more related to amazeui page check content please search the previous articles of the script house or continue to browse the following related articles, I hope you will support the script house more in the future!
<! -- The following three ways of writing are equivalent -->
<! -- Only the three types of email url number are built-in and can be extended -->
<input type="email"/>
<! -- js-pattern-xx where xx is the key in the pattern library -->
<input type="text" class="js-pattern-email"/>
<input type="text" pattern="^(.. .email regex...) $"/>