I am using the following Regex for validating MAC Addresses:
pattern("^([a-fA-f0-9]){12}(,s*([a-fA-f0-9]){12})*$")
and it works fine for the following input:
12aeabc11bba,662baea1abc2
I'd like to improve it to support the following MAC Address styles:
12-ae-ab-c1-1b-ba,66-2b-ae-a1-ab-c2
12ae-abc1-1bba,662b-aea1-abc2
12:ae:ab:c1:1b:ba,66:2b:ae:a1:ab:c2
12ae:abc1:1bba,662b:aea1:abc2
12aeabc11bba,662baea1abc2
It is not required for the Regex to support the following MAC Address styles, however it is OK if the Regex permits these:
12:ae:ab:c1:1b:ba,66-2b-ae-a1-ab-c2
2134:12:12:1234,ae-12-ae-42-62-ae
ae12-bc33-a122,fe12:ae12:ab54
ae12:bc33-a122
I am using Angular5
, and this validation is passed to the FormBuilder
validation, so I don't think I can put in multiple patterns.
this.requestForm = this.fb.group({
macAddresses: ['', [Validators.required, Validators.pattern("^([a-fA-f0-9]){12}(,s*([a-fA-f0-9]){12})*$")]]
});
Can anyone help solve the problem?
Whoever answers this question with the cleanest solution will get a bounty award of 100 rep