Skip to content

Instantly share code, notes, and snippets.

@kevinmmartins
Created April 12, 2022 09:13
Show Gist options
  • Save kevinmmartins/a59434b8e6f76c8d592635a33173be22 to your computer and use it in GitHub Desktop.
Save kevinmmartins/a59434b8e6f76c8d592635a33173be22 to your computer and use it in GitHub Desktop.
codility task
function validatePerson(fistName, result, lastName, email) {
if (!fistName) {
result = false
}
if (!lastName) {
result = false
}
if (email.match(/^[a-zAZ.]{1,64}@[a-zA-Z.]{1,64}$/) == null) {
result = false
}
return result
}
function validateCompany(companyName, result, phone) {
if (!companyName) {
result = false
}
if (phone.match(/^[\d]{3}-[\d]{3}-[\d]{4}$/) == null) {
result = false
}
return result
}
function solution() {
const isPerson = $("#type_person").is(":checked")
const isCompany = $("#type_company").is(":checked")
const companyName = $("#company_name").val()
const phone = $("#phone").val()
const fistName = $("#first_name").val()
const lastName = $("#last_name").val()
const email = $("#email").val()
let result = true
if (isPerson) {
result = validatePerson(fistName, result, lastName, email);
} else if (isCompany) {
result = validateCompany(companyName, result, phone);
} else {
return false
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment