35 lines
775 B
JavaScript
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;
|
||
|
}
|