Created
January 15, 2017 16:27
-
-
Save maxinspace/568368f3d4aba195d463e061841aee27 to your computer and use it in GitHub Desktop.
TestTask JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function solution() { | |
| const validationSelect = $("input:radio:checked").val(); | |
| switch (validationSelect) { | |
| case "person": | |
| return validatePerson(); | |
| break; | |
| case "company": | |
| return validateCompany(); | |
| break; | |
| default: | |
| return false | |
| }; | |
| }; | |
| function validatePerson() { | |
| return validatePresenceOf("#first_name") && | |
| validatePresenceOf("#last_name") && | |
| validateEmail("#email") | |
| }; | |
| function validateCompany() { | |
| return validateCompanyName() && | |
| validatePhone("#phone") | |
| }; | |
| function validatePresenceOf(fieldSelector) { | |
| const fieldValue = $(fieldSelector).val(); | |
| return (fieldValue == null || fieldValue == "") | |
| }; | |
| function validateCompanyName() { | |
| const fieldValue = $("#company_name").val(); | |
| return (fieldValue == null ) | |
| }; | |
| function validateEmail(emailSelector) { | |
| const emailValue = $(emailSelector).val(); | |
| const emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; | |
| return !!emailReg.test( emailValue ); | |
| }; | |
| function validatePhone(phoneSelector) { | |
| const phoneValue = $(phoneSelector).val(); | |
| const phoneReg = /^(\d{3}\.\d{3}\.\d{3})$/; | |
| return !!phoneReg.test( phoneValue ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment