Angularjs implementation

app.directive('checkDomainCommon', function () { return { restrict: 'A', require: 'ngModel', link(scope, ele, attrs, CTRL) {CTRL. $validators. CheckDomainCommon = function (modelVal) {/ / reg for regular domain regular let reg = / ^ [a zA - Z0-9] [9] - a - zA - Z0 - on conversion {0} (\. [a zA - Z0-9] [- a - zA - Z0-9] on conversion {0}) + \.? / if (attrs['required'] === undefined || attrs['required'] === false) { return true } else if(! modelVal){ return false; }else {// If (typeof modelVal!);}else {// If (typeof modelVal!); == 'string'){ console.error('the type of input value is not string,can not check domain format! '); return false; } // Comma delimited systems are compatible with semicolon delimited ones. Let domainArr = attrs['separatorReg'] let domainArr = attrs['separatorReg']? modelVal.split(new RegExp(attrs['separatorReg'])):modelVal.split(/,|; | - /); let domain = ""; let isOk = false; for (let i = 0; i < domainArr.length; i++) { domain = domainArr[i]; if (reg.test(domain)) { isOk = true; } else {break isOk = false;} else {break isOk = false; break; } } return isOk; }}}}});

Vue implementation

import Vue from 'vue' const domianReg = ''; // Register a global custom directive 'v-checkDomain' vue. directive('checkDomain', {// When a bound element is inserted into the DOM... inserted: function (el, binding, vNode) { el.addEventListener('keyup', Function (event) {// RemoveErrorStyle // Let isRequired = binding.Value.Required if (isRequired) {// RemoveErrorStyle if (! El. The value | | el. Value = = = ' ') {/ / do something with the error}} / / judgment regular let regex = binding. The value. The regex the if (regex = = = 'IpRegex') { if (! el.value.match(domainReg)) { //do something with error } } else if (! El.value. match(regex)) {//do something with error}})}}) // register a global custom directive 'v-checksubmit' vue. directive('checkSubmit', 'checkSubmit') {// When a bound element is inserted into the DOM... inserted: function (el, binding, vNode) { el.addEventListener('click', function (event) { let elements = document.getElementsByClassName('v-check') var evObj = document.createEvent('Event') evObj.initEvent('keyup', true, true) for (let element of elements) { element.dispatchEvent(evObj) } let errorInputs = document.getElementsByClassName('errorClssDom'); if (errorInputs.length === 0) { vNode.context.submit(); }})}})