mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00

* #521 Random MAC address generator * refactor(mac-address-generator): improved ux * refactor(mac-address-generator): improved ux --------- Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
32 lines
890 B
TypeScript
32 lines
890 B
TypeScript
import type { Ref } from 'vue';
|
|
import { useValidation } from '@/composable/validation';
|
|
|
|
const macAddressValidationRules = [
|
|
{
|
|
message: 'Invalid MAC address',
|
|
validator: (value: string) => value.trim().match(/^([0-9A-Fa-f]{2}[:-]){2,5}([0-9A-Fa-f]{2})$/),
|
|
},
|
|
];
|
|
|
|
function macAddressValidation(value: Ref) {
|
|
return useValidation({
|
|
source: value,
|
|
rules: macAddressValidationRules,
|
|
});
|
|
}
|
|
|
|
const partialMacAddressValidationRules = [
|
|
{
|
|
message: 'Invalid partial MAC address',
|
|
validator: (value: string) => value.trim().match(/^([0-9a-f]{2}[:\-. ]){0,5}([0-9a-f]{0,2})$/i),
|
|
},
|
|
];
|
|
|
|
function usePartialMacAddressValidation(value: Ref) {
|
|
return useValidation({
|
|
source: value,
|
|
rules: partialMacAddressValidationRules,
|
|
});
|
|
}
|
|
|
|
export { macAddressValidation, macAddressValidationRules, usePartialMacAddressValidation, partialMacAddressValidationRules };
|