Repository URL to install this package:
|
Version:
4.0.61 ▾
|
import { isString, isNumber } from 'exotic'
import isValidLength from './isValidLength'
const matchAlphaNumeric = /^[A-Za-z0-9 -]+$/
const matchAlphaNumericSpecialCharacters = /^[ A-Za-z0-9_@./#*!&+-]*$/
type CouponValueType = string | number
function isValidCoupon(value: CouponValueType): boolean {
const coerced = isNumber(value) ? String(value) : value
const isStringWithLength =
isString(coerced) &&
isValidLength(value, 2, 65) &&
matchAlphaNumericSpecialCharacters.test(value)
return isStringWithLength
}
export { isValidCoupon }