in hugegraph-hubble/hubble-fe/src/stores/GraphManagementStore/graphManagementStore.ts [252:315]
validate(type: 'new' | 'edit') {
const nameReg = /^[A-Za-z]\w{0,47}$/;
const hostReg = /((\d{1,3}\.){3}\d{1,3}|([\w!~*'()-]+\.)*[\w!~*'()-]+)$/;
const portReg = /^([1-9]|[1-9]\d{1}|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
const dataName = type + 'GraphData';
let readyToSubmit = true;
this.resetValidateErrorMessage();
if (!nameReg.test(this[dataName].name)) {
this[dataName].name.length === 0
? (this.validateErrorMessage.name = i18next.t(
'addition.store.required'
))
: (this.validateErrorMessage.name = i18next.t(
'addition.store.no-match-input-requirements'
));
readyToSubmit = false;
}
if (!nameReg.test(this[dataName].graph)) {
this[dataName].graph.length === 0
? (this.validateErrorMessage.graph = i18next.t(
'addition.store.required'
))
: (this.validateErrorMessage.graph = i18next.t(
'addition.store.no-match-input-requirements'
));
readyToSubmit = false;
}
if (!hostReg.test(this[dataName].host)) {
this[dataName].host.length === 0
? (this.validateErrorMessage.host = i18next.t(
'addition.store.required'
))
: (this.validateErrorMessage.host = i18next.t('addition.store.rule1'));
readyToSubmit = false;
}
if (!portReg.test(this[dataName].port)) {
this[dataName].port.length === 0
? (this.validateErrorMessage.port = i18next.t(
'addition.store.required'
))
: (this.validateErrorMessage.port = i18next.t('addition.store.rule2'));
readyToSubmit = false;
}
if (
dataName === 'newGraphData' &&
((this[dataName].username.length !== 0 &&
this[dataName].password.length === 0) ||
(this[dataName].username.length === 0 &&
this[dataName].password.length !== 0))
) {
this.validateErrorMessage.usernameAndPassword = i18next.t(
'addition.store.rule3'
);
readyToSubmit = false;
}
return readyToSubmit;
}