# Custom Rules
```html
{{ JSON.stringify(model, 0, 2) }}``` ```js export default { data () { return { model: { age: null, password: null, reenteredPassword: null }, rules: { age: [ { required: true, validator (rule, value) { if (!value) { return new Error('Age is required') } else if (!/^\d*$/.test(value)) { return new Error('Age should be an integer') } else if (Number(value) < 18) { return new Error('Age should be above 18') } return true }, trigger: ['input', 'blur'] } ], reenteredPassword: [ { validator: this.validatePasswordStartWith, message: 'Password is not same as re-entered password!', trigger: 'input' }, { validator: this.validatePasswordSame, message: 'Password is not same as re-entered password!', trigger: ['blur', 'password-input'] }, { required: true, message: 'Re-entered Password is required', trigger: ['input', 'blur'] } ] } } }, methods: { handlePasswordInput () { if (this.model.reenteredPassword) { this.$refs.reenteredPassword.validate('password-input', (errors => { if (!errors) { this.$NMessage.success('Valid') } else { console.log(errors) this.$NMessage.error('Invalid') } })) } }, handleValidateButtonClick (e) { e.preventDefault() this.$refs.form.validate(errors => { if (!errors) { this.$NMessage.success('Valid') } else { console.log(errors) this.$NMessage.error('Invalid') } }) }, validatePasswordStartWith (rule, value) { return this.model.password && this.model.password.startsWith(value) && this.model.password.length >= value.length }, validatePasswordSame (rule, value) { return value === this.model.password } } } ```