1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

setCustomValidity

Posted at
<form>
  <p><label>パスワード <input type=password name=password required pattern="[!-~]{5,}" title="英数字5文字以上"></label>
  <p><label>もういちど <input type=password name=password2 required pattern="[!-~]{5,}" title="英数字5文字以上"
                           oninput=" this.setCustomValidity(this.form.elements.password.value === this.value ? '' : this.getAttribute('data-password-mismatch-error')) "
                           data-password-mismatch-error="同じパスワードを記入してください。"></label>
  <p><button type=submit>設定</button>
</form>

setCustomValidity で独自のバリデーションエラーメッセージを設定することができます。エラー状態ではフォームを提出できず、ユーザーにエラーメッセージが表示されます。空文字列を指定するとエラー状態を解除できます。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?