Repository URL to install this package:
Version:
0.9.5 ▾
|
// 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