Skip to content

sameAs ​

The value equals a sibling field of the same object. Like Laravel's confirmed.

Signature ​

ts
function sameAs(field: string, msg?: Message): Action<unknown>

Parameters ​

ParameterTypeDescription
fieldstringField name in the same object
msgMessageCustom error message. A string with {params} or a function

Error codes ​

CodeWhenDefault message
sameAsThe values differMust match {field}

You can change the texts: see Messages & i18n.

Notes ​

  • Compared with the raw value of the field (before trim and other transforms). If the field is trimmed, trim the confirmation too.
  • Works only within one object. To compare with fields elsewhere use check and root.

Example ​

Password confirmation ​

ts
const Signup = object({
  password: pipe(string(), minLength(8)),
  passwordConfirm: pipe(string(), sameAs('password', 'Passwords do not match')),
});

See also ​

  • check — comparing with other fields