web2019/static/js/shop/validate.js
2024-01-09 10:14:53 +08:00

35 lines
775 B
JavaScript

import {validateJSON} from "./json_porter";
export const Validation = {
OK: 0,
Empty: 1,
Invalid: 2,
};
export function validateEmail(value) {
if (!value || value.trim() === '') {
return Validation.Empty
} else if (value && !value.match(/^\w+([\+\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)) {
return Validation.Invalid;
}
return Validation.OK;
}
export function validateNote(value) {
if (!value || value.trim() === '') {
return Validation.Empty
}
return Validation.OK;
}
export function validateJSONInput(value) {
if (!value || value.trim() === '') {
return Validation.Empty
} else if (value && !(validateJSON(value))) {
return Validation.Invalid;
}
return Validation.OK;
}