├── MIT.md ├── README.md ├── assets └── logo.png ├── index.html ├── script.js └── style.css /MIT.md: -------------------------------------------------------------------------------- 1 | ## Copyright 2023, [Julio Quezada] 2 | 3 | ###### Form Validator 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this Form Validator and associated documentation files, to deal in the Form Validator without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Form Validator, and to permit persons to whom the Form Validator is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Form Validator. 8 | 9 | THE FORM VALIDATOR IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE FORM VALIDATOR OR THE USE OR OTHER DEALINGS IN THE FORM VALIDATOR. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | logo 5 |
6 | 7 |

Form Validator

8 | 9 |
10 | 11 | 12 | 13 | # 📗 Table of Contents 14 | 15 | - [📗 Table of Contents](#-table-of-contents) 16 | - [📖 Form Validator ](#-form-validator-) 17 | - [🛠 Built With ](#-built-with-) 18 | - [Tech Stack ](#tech-stack-) 19 | - [Key Features ](#key-features-) 20 | - [🚀 Live Demo ](#-live-demo-) 21 | - [💻 Getting Started ](#-getting-started-) 22 | - [Prerequisites](#prerequisites) 23 | - [Setup](#setup) 24 | - [Install](#install) 25 | - [Usage](#usage) 26 | - [Run tests](#run-tests) 27 | - [Deployment](#deployment) 28 | - [👥 Authors ](#-authors-) 29 | - [🔭 Future Features ](#-future-features-) 30 | - [🤝 Contributing ](#-contributing-) 31 | - [⭐️ Show your support ](#️-show-your-support-) 32 | - [🙏 Acknowledgments ](#-acknowledgments-) 33 | - [❓ FAQ ](#-faq-) 34 | - [📝 License ](#-license-) 35 | 36 | 37 | 38 | # 📖 Form Validator 39 | 40 | Form Validator is a website that uses JavaScript to save data in the local storage, allows you to calculate the number of seats/price, it shows the occupied seats and the selected ones. It has a simple interfaces as it was only created to practice DOM manipulation. 41 | 42 | ## 🛠 Built With 43 | 44 | ### Tech Stack 45 | 46 |
47 | Frontend 48 | 53 |
54 | 55 | 56 | 57 | ### Key Features 58 | 59 | 60 | - **Validata data.** 61 | - **Clean code.** 62 | 63 |

(back to top)

64 | 65 | 66 | 67 | ## 🚀 Live Demo 68 | 69 | 70 | - [Live Demo Link](https://alejandroq12.github.io/form-validator/) 71 | 72 |

(back to top)

73 | 74 | 75 | 76 | ## 💻 Getting Started 77 | 78 | 79 | To get a local copy up and running, follow these steps. 80 | 81 | ### Prerequisites 82 | 83 | In order to run this project you need: 84 | 85 | - Only a web browser. 86 | 87 | ### Setup 88 | 89 | Clone this repository to your desired folder: 90 | 91 | - Open the terminal and use the following command: 92 | 93 | ``` 94 | cd my-folder 95 | git clone https://github.com/Alejandroq12/form-validator.git 96 | ``` 97 | 98 | 99 | ### Install 100 | 101 | Install this project with: 102 | 103 | For this project you just need a web browser. 104 | 105 | ### Usage 106 | 107 | To run the project, execute the following command: 108 | 109 | For this project you just need to open the index.html file with your browser. 110 | 111 | ### Run tests 112 | 113 | No tests were added to this project. 114 | 115 | 116 | ### Deployment 117 | 118 | You can deploy this project using: 119 | 120 | You can deploy this project using: GitHub Pages, 121 | - I used GitHub Pages to deploy my website. 122 | - For more information about publishing sources, see "[About GitHub pages](https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages#publishing-sources-for-github-pages-sites)". 123 | 124 |

(back to top)

125 | 126 | 127 | 128 | ## 👥 Authors 129 | 130 | 👤 **Julio Quezada** 131 | 132 | - GitHub: [Alejandroq12](https://github.com/Alejandroq12) 133 | - Twitter: [@JulioAle54](https://twitter.com/JulioAle54) 134 | - LinkedIn: [Julio Quezada](https://www.linkedin.com/in/quezadajulio/) 135 | 136 | 137 |

(back to top)

138 | 139 | 140 | 141 | ## 🔭 Future Features 142 | 143 | - [ ] **I will add a header and footer.** 144 | - [ ] **I will add another page** 145 | 146 |

(back to top)

147 | 148 | 149 | 150 | ## 🤝 Contributing 151 | 152 | Contributions, issues, and feature requests are welcome! 153 | 154 | Feel free to check the [issues page](../../issues/). 155 | 156 |

(back to top)

157 | 158 | 159 | 160 | ## ⭐️ Show your support 161 | 162 | If you like this project please give me a star. 163 | 164 |

(back to top)

165 | 166 | 167 | 168 | ## 🙏 Acknowledgments 169 | 170 | I would like to thank Traversy Media for his amazing content and his amazing learning platform. 171 | 172 |

(back to top)

173 | 174 | 175 | 176 | ## ❓ FAQ 177 | 178 | - **What did you learn?** 179 | 180 | - I learned a lot about data validation. 181 | 182 |

(back to top)

183 | 184 | 185 | 186 | ## 📝 License 187 | 188 | This project is [MIT](./MIT.md) licensed. 189 | 190 | 191 |

(back to top)

192 | 193 | -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alejandroq12/form-validator/6406151cb3412eadf04a351061fa6b811ab65525/assets/logo.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Form Validator 9 | 10 | 11 |
12 |
13 |

Register to my conference

14 |
15 | 16 | 22 | Error message 23 |
24 |
25 | 26 | 32 | Error message 33 |
34 |
35 | 36 | 42 | Error message 43 |
44 |
45 | 46 | 52 | Error message 53 |
54 | 55 |
56 |
57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | const form = document.getElementById('form'); 2 | const input = document.getElementById('username'); 3 | const email = document.getElementById('email'); 4 | const password = document.getElementById('password'); 5 | const password2 = document.getElementById('password2'); 6 | 7 | // Show input error message 8 | function showError(input, message) { 9 | const formControl = input.parentElement; 10 | formControl.className = 'form-control error'; 11 | const small = formControl.querySelector('small'); 12 | small.innerText = message; 13 | } 14 | // Show success outline 15 | function showSuccess(input) { 16 | const formControl = input.parentElement; 17 | formControl.className = 'form-control success'; 18 | } 19 | 20 | // Check email is valid 21 | function checkEmail(input) { 22 | const re = 23 | /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 24 | if (re.test(input.value.trim())) { 25 | showSuccess(input); 26 | } else { 27 | showError(input, 'Email is not valid'); 28 | } 29 | } 30 | 31 | // Check required fields 32 | function checkRequired(inputArr) { 33 | inputArr.forEach(function (input) { 34 | if (input.value.trim() === '') { 35 | showError(input, `${getFieldName(input)} is required`); 36 | } else { 37 | showSuccess(input); 38 | } 39 | }); 40 | } 41 | 42 | // Check input length 43 | function checkLength(input, min, max) { 44 | if (input.value.length < min) { 45 | showError( 46 | input, 47 | `${getFieldName(input)} must be at least ${min} characters` 48 | ); 49 | } else if (input.value.length > max) { 50 | showError( 51 | input, 52 | `${getFieldName(input)} must be less than ${max} characters` 53 | ); 54 | } else { 55 | showSuccess(input); 56 | } 57 | } 58 | 59 | // Check password match 60 | function checkPasswordsMatch(input1, input2) { 61 | if (input1.value !== input2.value) { 62 | showError(input2, 'Passwords do not match'); 63 | } 64 | } 65 | 66 | // Get fieldname 67 | function getFieldName(input) { 68 | return input.id.charAt(0).toUpperCase() + input.id.slice(1); 69 | } 70 | 71 | // Event Listeners 72 | form.addEventListener('submit', function (e) { 73 | e.preventDefault(); 74 | 75 | checkRequired([username, email, password, password2]); 76 | checkLength(username, 3, 15); 77 | checkLength(password, 6, 25); 78 | checkEmail(email); 79 | checkPasswordsMatch(password, password2); 80 | }); 81 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&display=swap'); 2 | 3 | * { 4 | box-sizing: border-box; 5 | } 6 | 7 | :root { 8 | --light-gray: #f5f5f5; 9 | --white: #fff; 10 | --dark-gray: #333; 11 | --green: #2ecc71; 12 | --red: #e74c3c; 13 | --light-blue: #3498db; 14 | } 15 | 16 | body { 17 | background-color: var(--light-gray); 18 | font-family: 'Open Sans', sans-serif; 19 | display: flex; 20 | align-items: center; 21 | justify-content: center; 22 | min-height: 100vh; 23 | margin: 0; 24 | } 25 | 26 | .container { 27 | background-color: var(--white); 28 | border-radius: 5px; 29 | box-shadow: 0 20px 20px rgba(0, 0, 0, 0.3); 30 | width: 96%; 31 | max-width: 500px; 32 | } 33 | 34 | h2 { 35 | text-align: center; 36 | margin: 0 0 20px; 37 | } 38 | 39 | form { 40 | padding: 30px 40px; 41 | } 42 | 43 | .form-control { 44 | margin-bottom: 10px; 45 | padding-bottom: 20px; 46 | position: relative; 47 | } 48 | 49 | .form-control label { 50 | color: var(--dark-gray); 51 | display: block; 52 | margin-bottom: 5px; 53 | } 54 | 55 | .form-control input { 56 | border: 2px solid var(--light-gray); 57 | border-radius: 5px; 58 | display: block; 59 | width: 100%; 60 | padding: 10px; 61 | font-size: 14px; 62 | } 63 | 64 | .form-control input:focus { 65 | outline: 0; 66 | border-color: var(--dark-gray); 67 | } 68 | 69 | .form-control.success input { 70 | border-color: var(--green); 71 | } 72 | 73 | .form-control.error input { 74 | border-color: var(--red); 75 | } 76 | 77 | .form-control small { 78 | color: var(--red); 79 | position: absolute; 80 | bottom: 0; 81 | left: 0; 82 | visibility: hidden; 83 | } 84 | 85 | .form-control.error small { 86 | visibility: visible; 87 | } 88 | 89 | .form button { 90 | cursor: pointer; 91 | background-color: var(--light-blue); 92 | border: 2px solid var(--light-blue); 93 | border-radius: 2px; 94 | color: var(--white); 95 | display: block; 96 | font-size: 16px; 97 | padding: 10px; 98 | margin-top: 10px; 99 | width: 100%; 100 | } 101 | --------------------------------------------------------------------------------