How do I combine custom RegEx rule and built in Indicative validators

I’m attempting to use Validator to verify several things about a MAC address sent in a request. I have a working RegEx expression for the format I’m expecting, and I’ve functionally tested it to verify its effectiveness. However, I would also like to apply required, and unique:units,mac_address.

I’ve discovered there is an issue with this:

const rules = {
      mac_address:[ 'required', 'unique:units,mac_address', 'notExists:units,mac_address', rule('regex', new RegExp('^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'))],

I’ve also tried creating a ‘notExists’ function as seen above by extending Validator, after getting the existsFn from the docs working. I experienced the same results even though I was able to use notExistsFn on rules without the rule('<validator>', <etc>) format.

I’m not quite sure how to make this work but I’d like a solution that provides all of the previously mentioned validations.

How can I make this work?

1 Like

Can you try this way, I used this way in my project

const rules = [
	rule('unique', 'units'),
	rule('notExists', 'units'),
	rule('regex', new RegExp('^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$')),