"src/utils/src/utils/regex.js" did not exist on "3f9b6187164b52d52fa4cc94272c673ca9e92ac4"
regex.js 1.27 KB
Newer Older
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1 2 3 4 5
const numberRegex = /^[0-9]+$/
const idRegex = /^[0-9]{11}$/
const emailRegex = /^([a-zA-Z0-9_\-.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
const phoneRegex = /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/
const lettersBlankSpacesRegex = /^([á-úÁ-Úa-zA-Z ])+$/
krlsnvz93's avatar
krlsnvz93 committed
6
const cmfRegex = /^([0-9-.])+$/
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
7 8 9 10 11 12 13 14 15 16 17 18
const lastNameRegex = /^([á-úÁ-Úa-zA-Z])+( [á-úÁ-Úa-zA-Z]+)?$/
const positiveNumberRegex = /^[0-9]+$/
const numbersRegex = /^(?!-0(\.0+)?$)-?(0|[1-9]\d*)(\.\d+)?$/

const isNumber = string => {
  return numberRegex.test(string)
}

const isId = string => {
  return idRegex.test(string)
}

Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
19 20 21 22
const isCmf = string => {
  return cmfRegex.test(string)
}

Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
const isEmail = string => {
  return emailRegex.test(string)
}

const isPhone = string => {
  return phoneRegex.test(string)
}

const isLettersWithBlankSpaces = string => {
  return lettersBlankSpacesRegex.test(string)
}

const isLastName = string => {
  return lastNameRegex.test(string)
}

const isPositiveNumber = string => {
krlsnvz93's avatar
krlsnvz93 committed
40
  return positiveNumberRegex.test(string)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
}

const isGpsCoordinate = string => {
  return numbersRegex.test(string)
}

export {
  isNumber,
  isId,
  isEmail,
  isPhone,
  isLettersWithBlankSpaces,
  isLastName,
  isPositiveNumber,
  isGpsCoordinate,
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
56
  isCmf,
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
57
}