Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui / src / forms / deps / isValidCoupon.tsx
Size: Mime:
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 }