[php] php
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- <?php
- echo '<!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Registration Form</title>
- <style>
- .error { color: red; font-size: 30px; }
- </style>
- </head>
- <body>
- <form id="registrationForm">
- User name: <input type="text" id="userName" name="userName"><br>
- Password: <input type="password" id="password" name="password"><br>
- Confirm Password: <input type="password" id="confirmPassword" name="confirmPassword"><br>
- Gender:
- <input type="radio" name="gender" value="Male"> Male
- <input type="radio" name="gender" value="Female"> Female<br>
- Email: <input type="text" id="email" name="email"><br>
- deptno: <input type="text" id="deptno" name="deptno"><br>
- deptname:
- <select id="deptname" name="deptname">
- <option value="Accounting">Accounting</option>
- <option value="Programming">Programming</option>
- <option value="Secretary">Secretary</option>
- </select><br>
- <input type="submit" value="Submit">
- <input type="reset" value="Reset">
- </form>
- <div id="result"></div>
- <script>
- document.getElementById(\'registrationForm\').onsubmit = function(event) {
- event.preventDefault();
- var userName = document.getElementById(\'userName\').value;
- var password = document.getElementById(\'password\').value;
- var confirmPassword = document.getElementById(\'confirmPassword\').value;
- var email = document.getElementById(\'email\').value;
- var deptno = document.getElementById(\'deptno\').value;
- var deptname = document.getElementById(\'deptname\').value;
- var genderInputs = document.getElementsByName(\'gender\');
- var gender = [...genderInputs].find(input => input.checked)?.value;
- var errorMessage = \'\';
- // Validation Logic
- if (!/^[A-Z][a-z]+ [A-Z][a-z]+$/.test(userName)) {
- errorMessage += \'User name must consist of 2 alphabetic parts separated by space each part must begin with a capital letter.<br>\';
- }
- if (!/^[A-Z]\\d{5}\\$$/.test(password)) {
- errorMessage += \'Password must begin with 1 uppercase letter followed by 5 digits and a dollar sign ($).<br>\';
- }
- if (password !== confirmPassword) {
- errorMessage += \'Passwords do not match.<br>\';
- }
- if (!/^\\w+@\\w+\\.\\w{2,3}$/.test(email)) {
- errorMessage += \'Email must follow the specified format.<br>\';
- }
- if (!/^\\d$/.test(deptno)) {
- errorMessage += \'Department number must be one digit.<br>\';
- }
- if (![\'Accounting\', \'Programming\', \'Secretary\'].includes(deptname)) {
- errorMessage += \'Department name must be from the list.<br>\';
- }
- // Display Results or Errors
- if (errorMessage) {
- document.getElementById(\'result\').innerHTML = \'<div class="error">\' + errorMessage + \'</div>\';
- } else {
- document.getElementById(\'result\').innerHTML = \'<div>\' +
- \'Employee Name is: \' + userName + \'<br>\' +
- \'Employee gender is: \' + gender + \'<br>\' +
- \'Working in department: \' + deptname + \' (deptno \' + deptno + \')<br>\' +
- \'Employee E-mail address: \' + email + \'<br>\' +
- \'</div>\';
- }
- };
- </script>
- </body>
- </html>';
Editor
You can edit this paste and save as new:
File Description
- php
- Paste Code
- 20 Apr-2024
- 3.13 Kb
You can Share it: