Skip to content

Instantly share code, notes, and snippets.

@OleksandrLz
Created March 5, 2018 08:35
Show Gist options
  • Select an option

  • Save OleksandrLz/ea900fa50569dec9f9f701a7e4288dcc to your computer and use it in GitHub Desktop.

Select an option

Save OleksandrLz/ea900fa50569dec9f9f701a7e4288dcc to your computer and use it in GitHub Desktop.
// e-mail
export default function validateEmail (email) {
const re = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
return re.test(email)
}
// name
export function nameContainsAlpha (value) {
return /^([а-яА-Яa-zA-ZёЁ]+['`\-,.]?[ ]?[a-zа-я]*)$/g.test(value)
}
// phone
export default function validatePhone (value) {
if (typeof value === 'undefined' || value === null || value === '') {
return true
}
if (!String(value).startsWith('+')) {
return false
}
return /^(\+|\d)[0-9]{10,16}$/.test(value)
}
// notSameAs
export default function (old) {
const check = function (value) {
const oldValue = ejectOldValue(old, this)
return value !== oldValue
}
return check
}
function ejectOldValue (old, context) {
const arr = old.split('.')
if (arr.length > 1) {
let val = context
arr.forEach(item => {
val = val[item]
})
return val
}
return context[old]
}
// passswordValidation
export function passwordContainsAlpha (value) {
return /[a-zA-Z]/.test(value)
}
export function passwordContainsNumeric (value) {
return /\d/.test(value)
}
export function passwordLength (value) {
return value.length >= 6 && value.length <= 20
}
export function passwordSpecialChar (value) {
return !(/["]/.test(value))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment