major refactor of web store into vue setup style declaration; reactivity debugging; order view has known refresh issues
This commit is contained in:
44
src/validate.js
Normal file
44
src/validate.js
Normal file
@@ -0,0 +1,44 @@
|
||||
export function isEmpty(v) {
|
||||
return v === null || typeof v === 'string' && v.trim() === ''
|
||||
}
|
||||
|
||||
export function validateRequired(v) {
|
||||
if (isEmpty(v))
|
||||
return 'Required'
|
||||
return true
|
||||
}
|
||||
|
||||
export function validateAmount(v) {
|
||||
if (isEmpty(v))
|
||||
return true
|
||||
const floatRegex = /^-?\d*(?:[.,]\d*?)?$/
|
||||
if (!floatRegex.test(v))
|
||||
return 'Amount must be a number'
|
||||
if (parseFloat(v) <= 0)
|
||||
return 'Amount must be positive'
|
||||
return true
|
||||
}
|
||||
|
||||
export function validateMax(v) {
|
||||
if (!isEmpty(minPrice.value) && !isEmpty(v) && parseFloat(v) < parseFloat(minPrice.value))
|
||||
return 'Must be greater than the minimum price'
|
||||
return true
|
||||
}
|
||||
|
||||
export function validateMin(v) {
|
||||
if (!isEmpty(maxPrice.value) && !isEmpty(v) && parseFloat(v) > parseFloat(maxPrice.value))
|
||||
return 'Must be less than the maximum price'
|
||||
return true
|
||||
}
|
||||
|
||||
export function validateTranches(v) {
|
||||
const i = parseInt(v)
|
||||
if (parseFloat(v) !== i)
|
||||
return 'Whole numbers only'
|
||||
if (i < 1)
|
||||
return 'Must have at least one tranche'
|
||||
if (i > 255)
|
||||
return 'Maximum 255 tranches'
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user