dockwa / simple-react-validator

A simple react form validator inspired by Laravel validation.
https://dockwa.github.io/simple-react-validator
MIT License
278 stars 78 forks source link

Regex validation #391

Closed haresh6x closed 2 years ago

haresh6x commented 2 years ago

Hi, according to the docs:

regex:pattern Must match a regex. Options: regex it must match. Note: if your regex uses a | or , or other special characters use the array syntax to define the rule.

How do i customise the message? For example I have a regex in place that allows input starting with T followed by numbers. The validation is working but I want to give message like "the field-name must start with T followed by numbers." Currently the validation says "the field-name must match the required pattern"

stuyam commented 2 years ago

The last option of the message method accepts options so you can do:

{this.validator.message('title', this.state.title, 'required|regex:abcd', {messages: {regex: 'This is a custom message'})}
haresh6x commented 2 years ago

The last option of the message method accepts options so you can do:

{this.validator.message('title', this.state.title, 'required|regex:abcd', {messages: {regex: 'This is a custom message'})}

Wow! Thanks alot. Suprised I didn't find it in documentation or might be i missed it.