I want to have one regular expression to validate following MAC address formats.
- 01-23-45-67-89-abor- 01-23-45-67-89-AB
- 01:23:45:67:89:abor- 01:23:45:67:89:AB
- 0123.4567.89abor- 0123.4567.89AB
- 0123456789abor- 0123456789AB
All of the above are valid MAC Address Formats.
MAC Address should have all CAPITAL letters or all small letters(but not both) of English alphabets from set [a-f A-F] .
Currently i am using 6 regex pattern and i have combined them using or for validation, which doesn't look good.
Here is my Javascript Code:
    var value='01-23-45-67-89-ab';
    var regex = new RegExp("^([0-9a-f]{2}){6}$");
    var regex1 = new RegExp("^([0-9A-F]{2}){6}$");
    var regex2 = new RegExp("^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$");
    var regex3 = new RegExp("^([0-9a-f]{2}[:-]){5}([0-9a-f]{2})$");
    var regex4 = new RegExp("^([0-9a-f]{4}[\\.]){2}[0-9a-f]{4}$");
    var regex5 = new RegExp("^([0-9A-F]{4}[\\.]){2}[0-9A-F]{4}$");
    if (regex.test(value) || regex1.test(value)|| regex2.test(value)|| regex3.test(value)|| regex4.test(value)|| regex5.test(value)){
            return true;
        }
    else{
        return false;
    }
Is ther a better way to combine them all without using or?
I am not good with regex.
Any Help would be appreciated.
 
    
 
    