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    
ui-component-library / src / forms / deps / isAlphaNumeric.ts
Size: Mime:
// import { isNumberOrString } from 'exotic'
import { isNumber, isString } from 'exotic'

const isNumberOrString = x => isNumber(x) || isString(x)
// @note - this old credit card match does global match
// and has no begin/end so it will trigger falsy
// /[a-zA-Z0-9]/g

const matchLetters = /([a-zA-Z])/
const matchNumbers = /([0-9])/
const matchAlphaNumeric = /^[A-Za-z0-9]+$/
const onlyAlphabets = /^[a-zA-Z]*$/
const matchCity = /^[A-Za-z -]*$/

type AlphaNumericDataTypes = string | number
/**
 * @alias isNumberOrStringOnly
 * @name isAlphaNumeric
 *
 * @description has only numbers & letters
 * @param {String | Number} value
 * @return {Boolean} is valid
 */
function isAlphaNumeric(value: AlphaNumericDataType): boolean {
  return isNumberOrString(value) && matchAlphaNumeric.test(value)
}

function isNumeric(value: AlphaNumericDataType): boolean {
  return isNumber(value)
}

function isAlphabet(value: AlphaNumericDataType): boolean {
  return value && isString(value) && onlyAlphabets.test(value)
}

function isValidCity(value: AlphaNumericDataType): boolean {
  return value && matchCity.test(value)
}

export { matchLetters }
export { matchNumbers }
export { isAlphaNumeric }
export { isAlphaNumeric as isNumberOrStringOnly }
export { isNumeric }
export { isValidCity }
export { isAlphabet }
export default isAlphaNumeric